使用MYECLIPSE正确导入STRUTS需要的JAR包之后,我建立一个ACTION类,然后继承ACTIONSUPPORT类,

2024-12-12 08:05:54
推荐回答(1个)
回答1:

因为ActionSupport是你整合了Spring之后用的,再Spring的包里,光用Struts2的话,Action是不用继续任何东西的,不过一般都会有一个baseaction,让你的action都去继承这个东西,里面带了点你比较常用的对象

public class BaseAction implements Serializable,RequestAware,SessionAware,ApplicationAware,ServletRequestAware,ServletResponseAware,ServletContextAware{
private static final long serialVersionUID = -8737956568774373323L;
protected Map request;
protected Map session;
protected Map application;
protected HttpServletRequest httpServletRequest;
protected HttpServletResponse httpServletResponse;
protected HttpSession httpSession;
protected ServletContext httpApplication;
public void setSession(Map session) {
this.session = session;
}
public void setRequest(Map request) {
this.request = request;
}
public void setApplication(Map application) {
this.application = application;
}
public void setServletRequest(HttpServletRequest httpServletRequest) {
this.httpServletRequest = httpServletRequest;
this.httpSession = httpServletRequest.getSession();
}
public void setServletResponse(HttpServletResponse httpServletResponse) {
this.httpServletResponse = httpServletResponse;
}
public void setServletContext(ServletContext servletContext) {
this.httpApplication = servletContext;
}
public String execute() throws Exception{
return "success";
}
}