无法在Struts动作类中获取请求属性 [英] Can't get request attribute in struts action class

查看:58
本文介绍了无法在Struts动作类中获取请求属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jsp页面.我正在iframe中调用jsp页面,并将新参数附加到url.

I have a jsp page. I am calling the jsp page in a iframe and appending new parameter to the url.

usrl看起来像

http:\ localhost:8080 \ Search.pp?blah = true;

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);
    }

然后在jsp页面中,我做类似

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); 

当从另一页面调用某项时,我使用此搜索"布尔变量来隐藏某些内容. 因此,如果用户单击此页面中的任何链接,它将再次返回到struts相同的动作类. 我的问题是,第一次一切正常.下次,我希望在struts动作中设置此变量,但看起来它返回的是null.

I use this "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.

推荐答案

请求属性只要存在问题的HTTP请求有效就可以使用.它在客户端实际发送时开始,并在客户端检索与HTTP请求关联的完整HTTP响应时结束.任何后续请求都是全新的,根本不包含先前请求的属性的副本.

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>

(JSTL fn:escapeXml()用于在重新显示用户控制的输入时防止您的站点受到XSS攻击)

(the JSTL fn:escapeXml() is to prevent your site from XSS attacks while redisplaying user-controlled input)

这篇关于无法在Struts动作类中获取请求属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆