• 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

struts2: how to set parameter?

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am adding a piece of struts2 code in an app that uses servlets, javascript form submission and scriplet code...its a mess.

But currently, my struts2 piece will forward the request based on certain criteria.

In this case if these conditions are true then control goes to some page, say apples.jsp. But this jsp page has scriplet code and expects certain parameters. Previously, before my struts2 code, these parameters were passed as 'hidden' values via JS form submission and forwarding from page w/out showing user anything.

ok so I am wondering if its possible to setParameter using struts2?

I have something like this code

I looked around and it seems the java servlet API's do not allow setParameter as its not job of a servlet but of a HTTP request.

A way around it would be for me to pass parameters by appending them to the page name using ?param=blah but that wont be 'hidden'. Also if I wish implement this approach, then is there a way to establish a variable that could be used in struts.xml?
so my struts.xml would become something like this

Thanks and sorry for big post
 
Bhaarat Sharma
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after a bit of reading up one viable solution is doing something like this

in the above, color, is a property in Fruits class. But still this parameter will be passed through url?parm=red which isnt hidden..

if someone can find a solution so the parameter is hidden i'd appreciate it.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know a way to do it that hides the variables, but it is certainly possible to specify a variable for a Struts 2 result. You'll see some examples of this in the struts.xml file inside the struts 2 Showcase war file that comes with the download. Example:

In the above code, myVariable represents a property of the Action class.
 
Bhaarat Sharma
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, dont think there is a way to do it. because java API itself doesnt support it.

oh well, I've decided to convert the forwarding page to struts2 as well so it will use properties rather than parameters.

Thanks for the help
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic