【struts2】Action类中获取session,request,response对象
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
publicclass IoCServlet extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware {
private Map session;
private HttpServletRequest request;
private HttpServletResponse response;
//set注入Session,struts2把session封装成了一个Map
publicvoid setSession(Map session) {
this.session= session;
}
//set注入request对象
publicvoid setServletRequest(HttpServletRequest request) {
this.request = request;
}
//set注入response对象
publicvoid setServletResponse(HttpServletResponse response) {
this.response = response;
}
@Override
public String execute() {
//方法中可以对session、request、response进行操作
......
return SUCCESS;
}
}
网络上志同道合,我们一起学习网络安全,一起进步,QQ群:694839022