Struts Forward to an Action from an to Action and URLs

R

rjweytens

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
 
O

Oscar kind

rjweytens said:
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
 
R

rjweytens

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 ---
 
O

Oscar kind

rjweytens said:
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
 
M

Murray

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?
 
R

rjweytens

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>
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top