Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action Form and HttpServletRequest

 
Maneesh Chauahn
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a question on the struts frame work. As we are using the ActionForm to get all the values defined in the JSP Page and used those variables in the action .
Now suppose a have a variable "aaa" (may be hidden) which is not defined in the actionForm. So can it is possible i get the value of this variable in the Action like

String value = httpServletRequest.getParameter("aaa")

IF it is not possible to get the value of variables which are defined in the JSP not defined in the ActionForm, Why so and how can used these types variables

Thanks in advance for your prompt answer
Maneesh Chauhan
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, let's make it clear that you can still access parameters the "old fashioned way" in an Action class. Since struts passes your execute method an instance of HttpServletRequest object, can put the code

in your Action class and it will work just fine regardless of whether you have defined "aaa" as a property in your ActionForm or not.

While it may be possible to access the parameter in the ActionForm this way, as far as I'm concerned there's generally no reason to do so. Even if you don't use the <html:xxx> tags in your JSP, any input field you define will be picked up by Struts and used to populate the property in the ActionForm that corresponds to the name of the input field. For example, if you have the entry:

Struts will still populate the property "aaa" in your ActionForm bean with the valuve "foo". The same is true if "aaa" is passed as a value in the query screen as in:

As long as the ActionForm associated with "/MyAction" has an "aaa" property, struts will populate it with the value "foo".

If you really really want to do this (Even though there's no need!), ActionForm has a reset() method that passes in an HttpServletRequest instance that you can override. Struts calls the reset method after a form is submitted, but before it calls the setters on the ActionForm.
[ February 05, 2007: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic