zoukankan      html  css  js  c++  java
  • 【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;
        }
    }
  • 相关阅读:
    SQL中存储过程与自定义函数的区别
    内置函数
    正则表达式
    HTML发展史
    触发器
    事务
    视图
    索引的使用
    存储过程和自定义函数的区别
    游标用法
  • 原文地址:https://www.cnblogs.com/cnsec/p/13286804.html
Copyright © 2011-2022 走看看