首页 > 代码库 > Action类中通过ServletActionContext来获取web资源

Action类中通过ServletActionContext来获取web资源

1 . 获取方法如下:

package com.xuzhiwen.test;

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

import org.apache.struts2.ServletActionContext;

public class ServletAction {
    
    public String getServletAction(){
        //request
        HttpServletRequest request = ServletActionContext.getRequest();
        //session
        HttpSession session = request.getSession();
        //servletContext
        ServletContext servletContext = ServletActionContext.getServletContext(); 
        return "success";
    }
}

 

Action类中通过ServletActionContext来获取web资源