gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 07:49:20 25 4
gpt4 key购买 nike

设置属性

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

最佳答案

From VoucherApproverListAction action class after success ,it is redirected to VoucherAction action class

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

关于java - 在 Struts 2 中的 request.getAttribute(..) 中获取 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14748698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com