1.Action类下的代码
public class ServletActionDemo extends ActionSupport { @Override public String execute() throws Exception { ActionContext context = ActionContext.getContext(); Map<String, Object> sessionMap = context.getSession(); Map<String, Object> applicationMap = context.getApplication(); System.out.println(sessionMap); System.out.println(applicationMap.get("pass")); //获取URL地址上的?后面的参数内容 // Map<String, Object> paramMap = context.getParameters(); // System.out.println(((String[])paramMap.get("username"))[0]); // context.put("name", "天恒"); HttpServletRequest request = ServletActionContext.getRequest(); ActionContext context = ServletActionContext.getActionContext(request); // context = ActionContext.getContext(); // context = ServletActionContext.getContext(); System.out.println(context.getSession()); return SUCCESS; } }
2.
public class ServletActionDemo2 extends ActionSupport implements ServletRequestAware{ private HttpServletRequest request; @Override public String execute(){ ActionContext context = ActionContext.getContext(); HttpServletRequest request = ServletActionContext.getRequest(); //request.getParameter("age") //context.getSession() System.out.println(request.getParameter("pass")); return SUCCESS; } @Override public void setServletRequest(HttpServletRequest request) { this.request = request; } }