Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > (struts) Dynamic path configuration/resolving

Reply
Thread Tools

(struts) Dynamic path configuration/resolving

 
 
Manish
Guest
Posts: n/a
 
      02-13-2007
I have a strange requirement herem, not sure if I can explain it
properly, but
let me try - I need to display different set of sites with dyamic
paths such
as -

http://xyz.com/people/1234/index.do?someparams=pqr
http://xyz.com/people/5678/index.do?someparams=pqr
http://xyz.com/people/1234/photos.do
http://xyz.com/people/5678/photos.do

Now - the numbers here (1234 or 567 will be generated dynamially and
the action
will be requested - but they should resolve to the same action say -
http://xyz.com/people/index.do?someparams=pqr and the action should
also get the
requested number in the path. Obviously it is not possible to add
configurations
for all those dynamic numbers, so there has to be only one action
mapped here.

So what I want is this http://xyz.com/people/1234/index.do?
someparams=pqr should
resolve to http://xyz.com/people/index.do?someparams=pqr and it should
also get
"1234" as part of the info.

How can I achieve this?? I have not done this before but I think this
sort of path manipulation should be possible.
Any pointers, help would be highly appreciated!!

TIA,
- Manish

 
Reply With Quote
 
 
 
 
J-P
Guest
Posts: n/a
 
      02-14-2007
I think you can use wildcards in the action definition like this:

<action-mappings>
<action path="**/mystuff"
type="test.action.TestAction"
scope="request">
<forward name="ok"
path="/mystuff.jsp"/>
</action>
</action-mappings>

Then by using following code you can parse the prefixing 'folder'
created dynamically.

public ActionForward execute(ActionMapping map, ActionForm form,
HttpServletRequest req, HttpServletResponse resp) throws Exception {

//
// map.getPath() returns the path used to access the Action.
// e.g. http://localhost:8080/Context/foo/bar.do would return /foo/bar
//
String path = map.getPath();
//Parse the prefixing "folder" from the path
//e.g. the "foo" from "/foo/bar/
String folder = path.substring(1,path.indexOf("/",1));

req.setAttribute("folder",folder);
return map.findForward("ok");
}

- J-P

Manish wrote:
> I have a strange requirement herem, not sure if I can explain it
> properly, but
> let me try - I need to display different set of sites with dyamic
> paths such
> as -
>
> http://xyz.com/people/1234/index.do?someparams=pqr
> http://xyz.com/people/5678/index.do?someparams=pqr
> http://xyz.com/people/1234/photos.do
> http://xyz.com/people/5678/photos.do
>
> Now - the numbers here (1234 or 567 will be generated dynamially and
> the action
> will be requested - but they should resolve to the same action say -
> http://xyz.com/people/index.do?someparams=pqr and the action should
> also get the
> requested number in the path. Obviously it is not possible to add
> configurations
> for all those dynamic numbers, so there has to be only one action
> mapped here.
>
> So what I want is this http://xyz.com/people/1234/index.do?
> someparams=pqr should
> resolve to http://xyz.com/people/index.do?someparams=pqr and it should
> also get
> "1234" as part of the info.
>
> How can I achieve this?? I have not done this before but I think this
> sort of path manipulation should be possible.
> Any pointers, help would be highly appreciated!!
>
> TIA,
> - Manish
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server.MapPath() croaking with "failed to map path", but path is legal awbacker@gmail.com ASP .Net 0 05-12-2005 10:50 PM
how to get application path? Is that my method in getting path wrong? James Java 2 12-07-2004 11:59 AM
absolute path versus relative path in JSP Matt Java 3 07-08-2004 08:31 PM
Bizzare: Invalid path to Access mdb, path is good Keith-Earl ASP .Net 1 05-03-2004 03:25 PM
Tomcat returning 404 error when using additional path (/servlet/myServlet/extra/path/info) Mupota Muchelemba Java 1 02-04-2004 12:43 AM



Advertisments