session

HttpSession session = request.getSession();
// 设置
session.setAttribute("id", id);

// 获取
String name = (String)session.getAttribute("id");

1. ActionContext

在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应(HttpServletResponse)操作. 我们需要在Action中取得request请求参数"username"的值:

ActionContext context = ActionContext.getContext(); 
Map params = context.getParameters(); 
String username = (String) params.get("username");

你可能感兴趣的:(session)