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";
    }
}

 

posted @ 2017-08-01 19:15  beibidewomen  阅读(795)  评论(0编辑  收藏  举报