Can't get request attribute in struts action class
I have a jsp page. I am calling the jsp page in a iframe and appending new parameter to the url.
The usrl looks like
http:\localhost:8080\Search.pp?blah=true;
So when as the search page called has got some filters so in the action class i have code like this
String Parameter =
request.getParameter(blah);
if (StringUtils.isNotEmpty(Parameter)) {
Search = Boolean.parseBoolean(campaignSearchParameter);
}
and then in the jsp page i do something like
final Boolean Search = (Boolean) request.getAttribute("blah") == null ? false : (Boolean) request
.getAttribute("blah");
request.setAttribute("blah",Search);
I use th开发者_开发问答is "Search" boolean variable to hide something when it's called from another page. So if the user clicks any links in this page it again goes back to struts same action class. My problem is that for the first time everything works fine. For next time i would expect in the struts action this variable to be set but looks like it's returning me null.
Request attributes live as long as the HTTP request in question lives. It starts whenever the client has actually sent it and it ends whenever the client has retrieved the complete HTTP response associated with the HTTP request. Any subsequent request is a brand new one which does not at all contain a copy of the attributes of the previous request.
You need to pass it as a request parameter instead. For example, as a hidden input field of a form of the other page.
<form ...>
...
<input type="hidden" name="blah" value="${fn:escapeXml(param.blah)}" />
</form>
(the JSTL fn:escapeXml()
is to prevent your site from XSS attacks while redisplaying user-controlled input)
精彩评论