Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I add a parameter into my forward?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using Struts 2. Before forwarding to a page, I want to add a parameter (named "result"), if possible, to my request, so that in the resulting JSP, I can access that parameter. How do I do that? Below is the action I have created ...


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

String result = "";
RoutingEngineCache routingEngineCache = RoutingEngineCache.getInstance();
if (routingEngineCache != null) {
result = routingEngineCache.refresh();
} else {
result = "Error: No routing engine cache instance returned.";
logger.error(result);
} // if

return mapping.findForward("refreshResultsPage");
} // execute


Thanks for your help, - Dave
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's unlikely to be Struts 2; did you mean Struts 1?
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's just say "Struts". If there a distinction between how it is done in varying versions, I am most grateful for any clarifications regarding each.

Thanks, - Dave
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't just say "Struts". Struts 1 and 2 are *completely* different.
 
Aditya Keyal
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try to add the value in the form of an attribute if that works for you ... That can be accomplished using the request object. In struts 1 it is available to you directly. In struts 2 you will have to use the ServletRequestAware interface to make that available in the method. refer ServletAware for further details

@Dave : David Newton is right you cant say struts and struts 2 to be the same. What code you have given is definately a struts 1 code not a struts 2. So next time be a little more precise coz things are very different between the 2.
 
Aditya Keyal
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one more work around for the same in struts 1 . (I am not sure how to implement in struts 2 ). You can create an instance of action forward object in the action and there when you assign the path to the jsp append the parameter using ?result=value ex: sample.jsp?result=value.

Though not a very neat way of doing things but a plausible alternative if qdding a parameter is a compulsary requirement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic