(struts) Dynamic path configuration/resolving

M

Manish

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 5678) 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
 
J

J-P

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top