aspose file tools*
The moose likes Struts and the fly likes struts2: how to set parameter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2: how to set parameter?" Watch "struts2: how to set parameter?" New topic
Author

struts2: how to set parameter?

Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
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


omnipresent
Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
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.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Bhaarat Sharma
Ranch Hand

Joined: Jun 04, 2007
Posts: 96
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
 
 
subject: struts2: how to set parameter?