(struts) Dynamic path configuration/resolving

Discussion in 'Java' started by Manish, Feb 13, 2007.

  1. Manish

    Manish Guest

    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
    Manish, Feb 13, 2007
    #1
    1. Advertising

  2. Manish

    J-P Guest

    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 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, Feb 14, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    808
  2. Katie Wright
    Replies:
    8
    Views:
    4,234
    Andrea Desole
    Jan 7, 2005
  3. Petros
    Replies:
    0
    Views:
    3,204
    Petros
    Aug 20, 2003
  4. ramakrishna
    Replies:
    3
    Views:
    1,196
    ramakrishna
    May 9, 2007
  5. Manish Hatwalne

    Dynamic path configuration/resolving

    Manish Hatwalne, Sep 11, 2007, in forum: Java
    Replies:
    5
    Views:
    358
    GArlington
    Sep 13, 2007
Loading...

Share This Page