Java得到上下文的绝对路径
2011-01-11 23:36
363 查看
1. /* 第一种:在 Struts2 当中,Struts1同样也可通过这种形式获取: */ 2. /* 获取 request 对象 */ 3. HttpServletRequest request = ServletActionContext.getRequest(); 4. /* 得到当前上下文绝对路径以保存图片 */ 5. String contextPath = request.getSession().getServletContext().getRealPath("//"); 6. 7. /* 第二种:在 Filter 当中: */ 8. public void init(FilterConfig config) throws ServletException { 9. /* 可将此参数放入到 Session 可供全局使用 */ 10. String contextPath = config.getServletContext().getRealPath("//"); 11. } 12. 13. /* 第三种 */ 14. String contextPath = request.getScheme()+"://"+request.getServerName() +":"+request.getServerPort()+request.getContextPath()+"/";
相关文章推荐
- JAVA 得到上下文绝对路径
- JAVA 得到上下文绝对路径
- 【java编程】IO流之得到指定目录下.java文件的绝对路径
- java的绝对路径,相对路径,上下文
- java中得到classpath和当前类的绝对路径的一些方法(路径中的%20"进行替换空格)
- java的绝对路径,相对路径,上下文
- JavaWeb(EE)相对路径_绝对路径详解与得到相关路径
- java ssh中得到上下文路径
- java中相对路径与绝对路径问题
- JAVA File的创建及相对路径绝对路径
- JAVA相对路径、绝对路径
- java中得到当前路径的方法
- Java相对路径/绝对路径总结(转)
- java区分绝对路径和相对路径的方法
- Java拿到工程的绝对路径相关问题-maven-resources-plugin
- java相对路径转换为绝对路径
- java获得绝对路径 的几种方法
- JAVA,JSP,Servlet获取当前工程路径-绝对路径
- java 路径访问全接触 url相对路径、绝对路径
- JavaWEB绝对路径