Struts2实现RequestAware接口页面输出失败

J2EE 码拜 9年前 (2015-10-16) 1251次浏览
最近学习Struts的几个获取页面属性的接口,发现使用RequestAware接口会使页面简洁很多,但是在实现过程中发现获取了request值但是页面输出失败。

这是实现各个接口的BaseAction

    public class BaseAction extends ActionSupport implements ServletContextAware, ServletRequestAware,
            ServletResponseAware, SessionAware, RequestAware, ApplicationAware, Serializable{
    private static final long serialVersionUID = 3998584345206401870L;
    protected ServletContext servletContext;
    protected HttpServletRequest httpServletRequest;
    protected HttpServletResponse httpServletResponse;
    protected Map<String, Object> session;
    protected Map<String, Object> request;
    protected Map<String, Object> application;
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }
    public void setServletRequest(HttpServletRequest httpServletRequest) {
        this.httpServletRequest = httpServletRequest;
    }
    public void setServletResponse(HttpServletResponse httpServletResponse) {
        this.httpServletResponse = httpServletResponse;
    }
    public void setSession(Map<String, Object> arg0){
        this.session = arg0;
    }
    public void setRequest(Map<String, Object> arg0) {
        this.request = arg0;
    }
    public void setApplication(Map<String, Object> application){
        this.application = application;
    }
}

这是Action实体

    public String list(){
            request.put("businesses", businessService.findAllBusiness());
            return "list";
    }

经过debug确认request有值。

下面是View层的jsp页面

<body>
    <h4>商家信息显示页面</h4>
    <s:if test="#request.businesses == null || #request.businesses.size() == 0">
        没有任何商家信息
    </s:if>
    <s:else>
        <table border="1" cellpadding="10" cellspacing="0">
            <tr>
                <td>编号</td>
                <td>商家名称</td>
                <td>删除</td>
            </tr>
            <!-- 循环输出数据 -->
            <s:iterator value="#request.businesses" var="business">
                <tr>
                    <td>${business.bid}</td>
                    <td>${business.bname}</td>
                    <a href="/Business/delete.action?bid=${bid}">
                        <input type="button" value="删除">
                    </a>
                </tr>
            </s:iterator>
        </table>
    </s:else>
</body>

下面是输出页面

Struts2实现RequestAware接口页面输出失败

解决方案:10分
${business.bid}这个是el表达式,

s标签貌似是这么写得<s:property value=”#business.bid”/>

解决方案:10分
<td><s:property value=”bid”/></td>  

<td><s:property value=”bname”/></td>  

解决方案:10分
你没有用<td>包起来

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Struts2实现RequestAware接口页面输出失败
喜欢 (0)
[1034331897@qq.com]
分享 (0)