java后台获取服务器的相对路径,不用request.getSession().getServletContext()和ServletActionContext
2014-04-14 15:12
661 查看
String rootPath = this.getClass().getResource("/").getPath(); //获取当前文件的路径
rootPath = rootPath.replaceAll("%20", " ");//空格转换的问题,显示的问题。
String webInfoPath = new File(rootPath).getParent();// WEB-INF 目录的物理路径
String abc = new File(webInfoPath).getParent();// WebRoot 目录的物理路径
abc = abc.replaceAll("\\\\", "/");
rootPath = rootPath.replaceAll("%20", " ");//空格转换的问题,显示的问题。
String webInfoPath = new File(rootPath).getParent();// WEB-INF 目录的物理路径
String abc = new File(webInfoPath).getParent();// WebRoot 目录的物理路径
abc = abc.replaceAll("\\\\", "/");
相关文章推荐
- javaweb中 ServletActionContext.getServletContext().getRealPath("")获得服务器路径
- ServletActionContext.getServletContext().getRealPath("/upload");myeclipseyeclipse获取路径不一样的原因
- eclipse java文件中ServletActionContext.getServletContext()报找不到getServletContext()方法
- jsp获取相对路径网址的方法 request.getContextPath()
- 在servlet 中使用 request.getSession().getServletContext().getRealPath("upload/" ); 获取不到 tomcat 服务器目录
- ServletActionContext.getRequest().getSession() 和 ActionContext.getContext().getSession()
- 直接用request.setAttribute()会报错,在这之前应该先让request获取ServletActionContext.getRequest();方法 // request.getAttribute同理
- 码农小汪-struts2学习8-Action中获取ActionContext,ServletActionContext,HttpServletRequest......
- ActionContext与ServletActionContext的区别及获取request、session等对象
- ServletActionContext.getRequest().getServletPath()错误的解决方法
- java.lang.NoSuchMethodError: javax.servlet.ServletRequest.getServletContext()Ljavax/servlet/ServletC
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- 在Servlet使用getServletContext()获取ServletContext对象出现java.lang.NullPointerException(空指针)异常的解决办法
- java获取服务器一些信息的方法(服务器地址/相对路径/端口/项目名字)
- Action获取传统域对象(HttpServletRequest、HttpSession、ServletContext)的三种
- 获取当前访问的部分虚拟路径(HttpContext.Current.Request.Url.GetLeftPart)
- java.lang.NoSuchMethodError: javax.servlet.ServletRequest.getServletContext()Ljavax/servlet/ServletC
- java取得项目工程---获取文件的相对路径问题---getResource()和getResourceAsStream以及路径问题
- JSP之项目路径问题(${pageContext.request.contextPath},<%=request.getContextPath()%>以及绝对路径获取)