File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How do I add a parameter into my forward? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How do I add a parameter into my forward?" Watch "How do I add a parameter into my forward?" New topic
Author

How do I add a parameter into my forward?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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

Joined: Sep 29, 2008
Posts: 12617

That's unlikely to be Struts 2; did you mean Struts 1?
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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

Joined: Sep 29, 2008
Posts: 12617

You can't just say "Struts". Struts 1 and 2 are *completely* different.
Aditya Keyal
Ranch Hand

Joined: Dec 01, 2008
Posts: 71
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 Webservices Blog
Aditya Keyal
Ranch Hand

Joined: Dec 01, 2008
Posts: 71
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I add a parameter into my forward?
 
Similar Threads
html:link passing parameter(s) to ActionForm
Adding the Parameter in HTTP Request Header
How can i add url parameter to my forward from the action ?
Create new params in results struts.xml
Forwarding a request to a different domain