第一种
public class UserAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
private Map session;
private Map request;
private Map application;
@Override
public String execute() throws Exception {
session = ActionContext.getContext().getSession();
request = (Map) ActionContext.getContext().get("request");
application = ActionContext.getContext().getApplication();
session.put("sk", "sv");
request.put("rk", "rv");
application.put("ak", "av");
System.out.println(name);
return ActionSupport.SUCCESS;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
第二种
public class DepAction extends ActionSupport implements RequestAware,SessionAware,ApplicationAware{
private Map<String, Object> request;
private Map<String, Object> session;
private Map<String, Object> application;
public void setRequest(Map<String, Object> request) {
this.request = request;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}
public void setApplication(Map<String, Object> application) {
this.application = application;
}
}
第三种
public class CarAction implements ServletRequestAware{
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public void setServletRequest(HttpServletRequest request) {
this.request = request;
this.session = request.getSession();
this.application = session.getServletContext();
}
}
第四种
public class HomeAction extends ActionSupport{
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public HomeAction (){
request = ServletActionContext.getRequest();
session = request.getSession();
application = session.getServletContext();
}
}