普通java类获取request并获取发布项目所在的物理路径
普通java类获取request并获取发布项目所在的物理路径
http://rainbowdesert.iteye.com/blog/1977979
博客分类:
- ActionContext ac = ActionContext.getContext();
- HttpServletRequest request = (HttpServletRequest)ac.get(ServletActionContext.HTTP_REQUEST);
ActionContext ac = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)ac.get(ServletActionContext.HTTP_REQUEST);
- /***************************************************************************
- * 函数名:getPath 作 用:获取服务器路径 参 数:request 返回值:字符串
- * By goodadd
- **************************************************************************/
- public String getPath(javax.servlet.http.HttpServletRequest request) {
- //String basePath = "/WEB-INF/classes/";
- String path = request.getSession().getServletContext().getRealPath(basePath);
- path = path.replace("/", "\\");
- return path + "\\";
- }
/*************************************************************************** * 函数名:getPath 作 用:获取服务器路径 参 数:request 返回值:字符串 * By goodadd **************************************************************************/ public String getPath(javax.servlet.http.HttpServletRequest request) { //String basePath = "/WEB-INF/classes/"; String path = request.getSession().getServletContext().getRealPath(basePath); path = path.replace("/", "\\"); return path + "\\"; }