JAVA 得到上下文绝对路径
2013-12-19 01:37
218 查看
/* 第一种:在 Struts2 当中,Struts1同样也可通过这种形式获取: */ /* 获取 request 对象 */ HttpServletRequest request = ServletActionContext.getRequest(); /* 得到当前上下文绝对路径以保存图片 */ String contextPath = request.getSession().getServletContext().getRealPath("//"); /* 第二种:在 Filter 当中: */ public void init(FilterConfig config) throws ServletException { /* 可将此参数放入到 Session 可供全局使用 */ String contextPath = config.getServletContext().getRealPath("//"); } /* 第三种 */ String contextPath = request.getScheme()+"://"+request.getServerName() +":"+request.getServerPort()+request.getContextPath()+"/";
相关文章推荐
- Java得到上下文的绝对路径
- JAVA 得到上下文绝对路径
- java的绝对路径,相对路径,上下文
- 【java编程】IO流之得到指定目录下.java文件的绝对路径
- java中得到classpath和当前类的绝对路径的一些方法(路径中的%20"进行替换空格)
- java的绝对路径,相对路径,上下文
- JavaWeb(EE)相对路径_绝对路径详解与得到相关路径
- java ssh中得到上下文路径
- Java中的绝对路径和相对路径
- 取Java绝对路径的方法
- java中得到当前路径
- java.io.File中的绝对路径和相对路径
- Java获得项目绝对路径方法总结
- Python怎样得到资源文件的绝对路径
- JAVA怎样得到当前程序所在文件夹的路径
- java getDocumentBase() 得到的文件夹路径
- 用JAVA扫描指定文件夹下面所有以.txt结尾的文件,并将其绝对路径输出
- java_Web_中相对路径绝对路径问题总结
- Java,JSP,Servlet获取当前工程路径(绝对路径)问题解析
- Java基础知识强化之IO流笔记14:递归之输出指定目录下所有java文件绝对路径的案例