• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I add a parameter into my forward?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't just say "Struts". Struts 1 and 2 are *completely* different.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic