java ,js获取web工程路径】的更多相关文章

一.java获取web工程路径 1),在servlet可以用一下方法取得: request.getRealPath(“/”) 例如:filepach = request.getRealPath(“/”) ”//upload//”; 2),不从jsp,或servlet中获取,只从普通java类中获取: String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); SAXReader()…
function getRealPath(){      //获取当前网址,如: http://localhost:8083/myproj/view/my.jsp       var curWwwPath=window.document.location.href;       //获取主机地址之后的目录,如: myproj/view/my.jsp      var pathName=window.document.location.pathname;      var pos=curWwwPa…
/** * 获得站点url * @return */ public String getWebUrl(){ String url = getRequest().getScheme() + "://" + getRequest().getServerName(); if(getRequest().getServerPort()!=80){ url+= ":" + getRequest().getServerPort(); } url+=getRequest().get…
引言 在web项目开发过程中,可能会经常遇到要获取项目根路径的情况,那接下来我就总结一下,java中获取项目根路径的7种方法,主要是通过thisClass和System,线程和request等方法. (1):this.getClass().getResource("/"): (2):file.getCanonicalPath(): (3):this.getClass().getClassLoader(): (4):System.getProperty("user.dir&qu…
//js获取项目根路径,如: http://localhost:8083/uimcardprj function getRootPath(){ //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp var curWwwPath=window.document.location.href; //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp var pathName=window.document.…
1)获取web上下文路径 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取ServletContext对象 //this.getServletConfig().getServletContext(); //等同于下面一句,因为创建getServletContext必须要通过getServletConfig对象…
/** * 获取web应用路径 * @Description : 方法描述 * @Method_Name : getRootPath * @return * @return : String * @Creation Date : 2013-12-13 下午9:09:28 * @version : v1.00 * @throws UnsupportedEncodingException * @Author : zyn * @Update Date : * @Update Author : zyn…
在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getProperty("user.dir")获取你工程的绝对路径. 另:在Jsp,Servlet,Java中详细获得路径的方法! 1.jsp中取得路径:以工程名为TEST为例:(1)得到包含工程名的当前页面全路径:request.getRequestURI()结果:/TEST/test.jsp(2)…
一.获得都是当前运行文件在服务器上的绝对路径在servlet里用:this.getServletContext().getRealPath(); 在struts用:this.getServlet().getServletContext().getRealPath(); 在Action里用:ServletActionContext.getRequest().getRealPath(); 以上三个获得都是当前运行文件在服务器上的绝对路径其实:request.getRealPath("url"…
不使用Spring,怎样能在Listener启动的Thread中获取web目录,还真不完全确定.其实我觉得实际代码也很简单.就是基于普通的listener,然后在listener中获取web目录并放到JRE全局变量中. 但使用Spring,就可以用一种比较优雅的方式来获取了. 在web.xml中的<web-app>节点内加入: <context-param> <param-name>webAppRootKey</param-name> <param-v…