1)获取web上下文路径 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取ServletContext对象 //this.getServletConfig().getServletContext(); //等同于下面一句,因为创建getServletContext必须要通过getServletConfig对象…
一.java获取web工程路径 1),在servlet可以用一下方法取得: request.getRealPath(“/”) 例如:filepach = request.getRealPath(“/”) ”//upload//”; 2),不从jsp,或servlet中获取,只从普通java类中获取: String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); SAXReader()…
/** * 获取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…
一.获得都是当前运行文件在服务器上的绝对路径在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…
File f = new File(WebPath.class.getResource("/").getPath()); String path = f.getParentFile().getParent(); 第一行获取到的是classpath的路径如:file:/E:/Workspace_idea/chicken/target/test-classes/     此处是用junit跑的 第二行获取到 E:\Workspace_idea\chicken 正确的项目路径 Test.cl…
1.先获取 serlvetContext对象 2.调用getResourceAsStream  在方法里 "\"表示当前web的根目录  还要拼接上具体的文件路径 ServletContext context = getServletContext(); InputStream path1 = context.getResourceAsStream("/WEB-INF/userInfo.properties");…
import javax.servlet.ServletContext; import org.springframework.web.context.ServletContextAware; /** * @author Administrator * */public class PayUtil implements ServletContextAware{ public ServletContext context ;    public static String PATH = "&quo…
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…
①HttpServletRequest的getParameter()方法. ②HttpServletRequest的getParameterValues()方法. ③HttpServletRequest的getParameterMap()方法.…