`

struts2 adtion 中获得获得和设置application,request,session,response

阅读更多

EmployeeAction.java

--------------------------------------

 

 

package org.taink.struts.action;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

public class EmployeeAction {

    public String execute() {
        ActionContext actionContext = ActionContext.getContext();
        actionContext.getApplication().put("application", "application 应用范围");
        System.out.println(actionContext.getApplication().get("application"));
        actionContext.getSession().put("session", "session 应用范围");
        System.out.println(actionContext.getSession().get("session"));
        actionContext.put("request", "request 应用范围");
        System.out.println(actionContext.get("request"));
        return "success";
    }

    public String test() {
        ServletContext servletContext = ServletActionContext.getServletContext();
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        HttpSession session = request.getSession();
        request.setAttribute("request", "request**应用范围");
        session.setAttribute("session", "session**应用范围");
        servletContext.setAttribute("application", "application**应用范围");
        return "success";
    }

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics