在Struts 2中的request.getAttribute(..)中获取Null

时间:2013-02-07 10:21:15

标签: java parameters struts2

设置属性

public class VoucherApproverListAction extends ActionSupport implements
SessionAware, ServletRequestAware, Preparable {
private HttpServletRequest servletRequest;

    public HttpServletRequest getServletRequest() {
        return servletRequest;
    }


    @Override
    public void setServletRequest(HttpServletRequest servletRequest) {
        this.servletRequest=servletRequest;
    }

public void prepare() throws Exception {
servletRequest.setAttribute("id",tCaseVouchrDto.getId());
}
}

获取属性

 public class VoucherAction extends ActionSupport implements
    SessionAware, ServletRequestAware, Preparable {
    private HttpServletRequest servletRequest;

        public HttpServletRequest getServletRequest() {
            return servletRequest;
        }


        @Override
        public void setServletRequest(HttpServletRequest servletRequest) {
            this.servletRequest=servletRequest;
        }

    public void prepare() throws Exception {
   String paramValue = (String)servletRequest.getAttribute("id");
        logger.info("@-----Id===-----@" + paramValue);
    }
    }

从成功后的VoucherApproverListAction动作类中,它被重定向到VoucherAction动作类在paramValue中获取null

1 个答案:

答案 0 :(得分:1)

  

成功之后来自VoucherApproverListAction动作类,它是   重定向到VoucherAction操作类

这是问题,如果您发送重定向请求属性会丢失。您需要在下一个请求之前传递参数或将其保存在会话中。