Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

(struts)  Dynamic path configuration/resolving

Thread view: 
Manish - 13 Feb 2007 09:01 GMT
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-P - 14 Feb 2007 08:49 GMT
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

> I have a strange requirement herem, not sure if I can explain it
> properly, but
[quoted text clipped - 29 lines]
> TIA,
> - Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.