转载:http://blog.csdn.net/piaoxuan1987/article/details/8541839 equest.getRealPath() 这个方法已经不推荐使用了,代替方法是: request.getSession().getServletContext().getRealPath() 从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 S…
从request获取各种路径总结 request.getRealPath("url"); // 虚拟目录映射为实际目录 request.getRealPath("./");    // 网页所在的目录 request.getRealPath("../"); // 网页所在目录的上一层目录 request.getContextPath();    // 应用的web目录的名称 如http://localhost:7001/bookStore/ /b…
equest.getRealPath() 这个方法已经不推荐使用了,代替方法是: request.getSession().getServletContext().getRealPath() 在servlet里用this.getServletContect().getRealPath() 在struts里用this.getServlet().getServletContext().getRealPath() 在Action里用ServletActionContext.getRequest().g…
一.获得都是当前运行文件在服务器上的绝对路径 在servlet里用: this.getServletContext().getRealPath() 在struts用: this.getServlet().getServletContext().getRealPath() 在Action里用: ServletActionContext.getRequest().getRealPath(); 以上三个获得都是当前运行文件在服务器上的绝对路径 其实: request.getRealPath("url&…
页面跳转总结 JSP中response.sendRedirect()与request.getRequestDispatcher().forward(request,response)这两个对象都可以使页面跳转,但是二者是有很大的区别的,分条来说,有以下几点: ①response.sendRedirect(url)-----重定向到指定URL request.getRequestDispatcher(url).forward(request,response) -----请求转发到指定URL ②r…
JSP取得绝对路径 在JavaWeb开发中,常使用绝对路径的方式来引入JavaScript和CSS文件,这样可以避免因为目录变动导致引入文件找不到的情况,常用的做法如下: 一.使用${pageContext.request.contextPath} 代码” ${pageContext.request.contextPath}”的作用是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的. 例如: 1 <!--使用绝对路径的方式引入CSS文件--> 2 <link rel="…
在项目页面中,总会引入一些js和css,相对路径or绝对路径的选择就显得至关重要了!下面是项目中遇到的问题和解决方案,做一下记录! 环境: myEclipse创建工程,使用jsp+css+js,项目目录为: 我们设置项目的初始页面为login.jsp,即在web.xml中配置 <welcome-file-list> <welcome-file>portal/login.jsp</welcome-file> </welcome-file-list> 待续 --…
正确流程应该是 import javax.servlet.http.HttpServletRequest; HttpServletRequst request = ServletActionContext.getRequest(); request.setAttribute(arg0,arg1); // request.getAttribute同理…
从request获取各种路径总结 request.getRealPath("url"); // 虚拟目录映射为实际目录 request.getRealPath("./");    // 网页所在的目录 request.getRealPath("../"); // 网页所在目录的上一层目录 request.getContextPath();    // 应用的web目录的名称 例如     http://localhost:8080/bookSto…
从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+&q…