Struts Forward to an Action from an to Action and URLs

Discussion in 'Java' started by rjweytens, Jun 22, 2004.

  1. rjweytens

    rjweytens Guest

    Hello,

    I am in the process of developing a web app using Struts. I have a
    situation where I am calling an action to add some information to a
    database, and if the add is successful, the action will forward to
    another action that brings up a confirmation page that shows the id #
    of the record that was added along with the added information. When
    the confirmation page comes up, the URL in the page is the URL for the
    action that added the record to the database, not the URL for the
    action that generated the confirmation page. Therefore, when the
    refresh button is pressed, the action will is executed again and
    another record is added to the database.

    I've added the redirect="true" parameter to my actions, but that did
    not change the URL. I have also read about using tokens, but it seems
    to me that the URL should stay current with the page. Any
    suggestions?

    Thanks
     
    rjweytens, Jun 22, 2004
    #1
    1. Advertising

  2. rjweytens

    Oscar kind Guest

    rjweytens <> wrote:
    > I am in the process of developing a web app using Struts.

    [...]
    > When the confirmation page comes up, the URL in the page is the URL for
    > the action that added the record to the database, not the URL for the
    > action that generated the confirmation page. Therefore, when the
    > refresh button is pressed, the action will is executed again and
    > another record is added to the database.
    >
    > I've added the redirect="true" parameter to my actions, but that did
    > not change the URL. I have also read about using tokens, but it seems
    > to me that the URL should stay current with the page. Any
    > suggestions?


    Instead of using an ActionForward to another view, try redirecting to
    another action. This confirmation action basically does nothing but return
    an ActionForward to the confirmation view.


    kind regards,
    Oscar

    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, Jun 22, 2004
    #2
    1. Advertising

  3. rjweytens

    rjweytens Guest

    Oscar,

    I don't follow you. I am forwarding from an Action to another Action,
    which is what I believe you are suggesting I do.

    i.e.

    User presses submit button ---> AddAction ---> Confirmation Action ---
    > Confirmation Page
     
    rjweytens, Jun 23, 2004
    #3
  4. rjweytens

    Oscar kind Guest

    rjweytens <> wrote:
    > I don't follow you. I am forwarding from an Action to another Action,
    > which is what I believe you are suggesting I do.
    >
    > i.e.
    >
    > User presses submit button ---> AddAction ---> Confirmation Action
    > ---> Confirmation Page


    I meant something like this:
    1. User presses submit
    2. AddAction adds record
    3. AddAction redirects to confirmation URL (i.e. goes to browser).
    4. User's browser goes to confirmation URL
    5. ConfirmAction forwards to confirmation view
    6. Confirmation view shows confirmation.

    Step 4 is the important one: because the application uses the user's
    browser as an intermediate step, the URL is updated correctly.

    AFAIK, this should work. If not, I've some troubleshooting to do myself.


    Oscar

    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, Jun 23, 2004
    #4
  5. rjweytens

    Murray Guest


    > I've added the redirect="true" parameter to my actions, but that did
    > not change the URL. I have also read about using tokens, but it seems
    > to me that the URL should stay current with the page. Any
    > suggestions?
    >
    > Thanks


    redirect="true" should change the URL since it issues a client-side
    redirect. Maybe you put it on the wrong forward? Or didn't restart your
    server/context?
     
    Murray, Jun 23, 2004
    #5
  6. rjweytens

    rjweytens Guest

    Here is the relevant section of my struts-config. See that the AddRFC
    action forwards to the ConfNew action. ConfNew then forwards to
    confNew.jsp. Hopefully this will help.

    Thanks for your help thus far.

    <!-- New RFC Page Action -->
    <action path="/New"
    type="rfc.NewRFCAction"
    redirect="true"
    scope="session">
    <forward name="success" path="/new.jsp"/>
    <forward name="error" path="/index.jsp"/>
    </action>

    <!-- Add RFC Action -->
    <action path="/AddRFC"
    type="rfc.AddRFCAction"
    redirect="true"
    name="RFCActionForm"
    scope="request"
    input="/new.jsp"
    validate="true">
    <forward name="success" path="/ConfNew.do"/>
    <forward name="error" path="/new.jsp"/>
    </action>

    <!-- Confim RFC Add/Edit Page Action -->
    <action path="/ConfNew"
    type="rfc.ConfRFCAction"
    redirect="true"
    name="RFCActionForm"
    scope="request"
    validate="false">
    <forward name="success" path="/confNew.jsp"/>
    <forward name="error" path="/confNew.jsp"/>
    </action>

    <!-- Log out of application Action -->
    <action path="/Logout"
    type="rfc.LogoutAction"
    redirect="true"
    scope="request">
    <forward name="success" path="/index.jsp"/>
    <forward name="error" path="/index.jsp"/>
    </action>
     
    rjweytens, Jun 23, 2004
    #6
  7. rjweytens

    rjweytens Guest

    Still no resolution yet.
     
    rjweytens, Jun 25, 2004
    #7
    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. Kaidi
    Replies:
    5
    Views:
    505
    Andrew Thompson
    Jan 4, 2004
  2. Gray
    Replies:
    0
    Views:
    663
  3. avrootshell
    Replies:
    3
    Views:
    1,338
    Manish Pandit
    Oct 19, 2006
  4. Q1tum
    Replies:
    3
    Views:
    20,933
    kremsoft
    Nov 24, 2009
  5. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    776
    Sriram Srivatsan
    Aug 12, 2008
Loading...

Share This Page