• Post Reply Bookmark Topic Watch Topic
  • New Topic

struts action forward problem!

 
ahsan mir
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my action class whenever i do a forward to a success jsp page the whole struts url gets forwarded as well.as a result the jsp page behaves as part of the struts application, how can i get round this. the jsp i want to get forwarded to is routed through a servlet which populates the jsp with some option values. how can i get the simple jsp page with no struts url attached.
i am using 'return mapping.findforward('success.jsp')'. Whts the difference between this and 'return new ActionForward('success.jsp').

thanks in advance.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want the URL to change when you forward to a JSP, you must specify redirect="true" when you define the forward. If you're creating the ActionForward dynamically, you must use the constructor that allows you to specify whether or not the forward is a redirect. Example:

One word of caution, though: When you redirect, you lose any information stored in the HTTPServletRequest, so to pass information to the JSP, you must either store it in the session or pass it with query string parameters.
i am using 'return mapping.findforward('success.jsp')'. Whts the difference between this and 'return new ActionForward('success.jsp').

The first refers to a named forward that you've defined in your struts-config.xml file. The second dynamically creates an ActionForward pointing to a specific URL.
 
ahsan mir
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, it works now.
what do you mean by:
When you redirect, you lose any information stored in the HTTPServletRequest, so to pass information to the JSP, you must either store it in the session or pass it with query string parameters.
.
In my ActionForward i have added the servlet path for the jsp , and its showing the correct jsp.Is that what you mean?
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!