转自:http://veryls.iteye.com/blog/239830
假定你的web application 名称为news,你在浏览器中输入请求路径:
http://localhost:8080/news/main/list.jsp
则执行下面向行代码后打印出如下结果:
1、 System.out.println(request.getContextPath()); //可返回站点的根路径。也就是项目的名字
打印结果:/news
2、System.out.println(request.getServletPath());
打印结果:/main/list.jsp
3、 System.out.println(request.getRequestURI());
打印结果:/news/main/list.jsp
4、 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\news\test
相关推荐
Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别
NULL 博文链接:https://javachikuang.iteye.com/blog/262264
request.getcontextPath()详解
java中request.getcontextPath()的意思.doc
String getRequestURI() StringBuffer getRequestURL() String getContextPath() ---web应用的名称 String getQueryString() ---- get提交url地址后的参数字符串 username=zhangsan&password=123 注意:request...
response.sendRedirect(request.getContextPath()+"/admin/login.jsp"); } public void register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //...
所有的jsp页面中的链接 添加 request.getContextPath() , 确保路径正确使用!! 代码中使用到了重定向等页面跳转,添加 request.getContextPath() , 确保路径正确使用!! dao 层中的接口不要随意修改,如果需要...
所有的jsp页面中的链接 添加 request.getContextPath() , 确保路径正确使用!! 代码中使用到了重定向等页面跳转,添加 request.getContextPath() , 确保路径正确使用!! dao 层中的接口不要随意修改,如果需要...
将JavaScript对象类型的参数通过JSON.stringify转换成字符串传递时,IE5、6、7、8会报:“JSON”未定义 的...解决方法:路径/json2.js">或者<script src="<%=request.getContextPath()%>/passripts/json2.js"></script>
var so = new SWFObject("<%=request.getContextPath()%>/js/player/CuPlayerMiniV4.swf","CuPlayerV4","600","410","9","#000000"); so.addParam("allowfullscreen","true"); so.addParam("allowscriptaccess",...
dwr开发包,常规客户端...<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/TestService.js'> <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'> ...
通过eval()函数可以将JSON字符串转化...String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOC
My97DatePicker日期控件使用引入js脚本目录,注意必须用<%=request.getContextPath() %>来获取项目根目录+脚本目录的方式,否则日期控件会无效!!! <script type="text/javascript" src="<%=request....
一 get和post的区别 二 实战(post方式提交) 1、login.jsp <%@ page language=java import=java.util.* contentType=text/html; charset=utf-8 %> <% String path = request.getContextPath(); ...
<script type="text/javascript" src="<%=request.getContextPath()%>//res/js/float.js"> var div1= new floatFrame( "id", "style", "title", "content", speed, startPositionX, startPositionX, ...
分享给大家供大家参考,具体如下: 1. css代码:index4.css @CHARSET "UTF-8"; .sd{ font-weight: bold; color: black;... background: red;...Stringpath = request.getContextPath(); StringbasePath = reque
String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD H
本文实例讲述了JSP实现简单的用户登录并...String path = request.getContextPath(); String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”; %>
String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML> <html> <head> ...
String graphURL =request.getContextPath+"/servlet/DisplayChart?filename="+filename;生成filename路径,而我运行不出来,而是根据文档 变成ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,...