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
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 ]