struts2 中有多种方法,可以在 action 获取到request和session。
获取request方法:
HttpServletRequest request = ServletActionContext.getRequest();
request.setAttribute("requestValue", "this is the test_value");
或者
Map<String,Object> request = (Map<String,Object>) ActionContext.getContext().get("request");
request.put("hello", "this is hello value");
获取session方法:
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("sessionValue", "this is the session_value");
或者
Map<String,Object> session = ActionContext.getContext().getSession();
session.put("ok", "hello");
时间: 2024-11-10 14:28:39