request获取路径的方式和区别
2016-01-07 19:43
786 查看
假定你的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
出处:http://talentnba.iteye.com/blog/344595
相关文章推荐
- [leetcode] 303. Range Sum Query - Immutable
- UI课程(图片动画/视图控制器/自定义视图/循环导入)
- UI课程(标签/文本输入框/图片/按钮/代理)
- UI布局(Layout)
- UIImageView 的 contentMode
- 蓝懿IOS学习之UITableView
- UITextFiled的LeftView
- 关于UITextView的几种回收键盘的方法
- 程序员面试问题1:数组问题 Programming Interview Questions 1: Array Pair Sum
- php生成UUID
- django实现用户登陆访问限制@login_required
- PV、UV、UIP、VV、CPC、CPM、RPM、CTR是什么意思?
- 使用druid连接池的超时回收机制排查连接泄露问题
- 样例问题 Example question for A4M33MPV course
- 出现could not build module foundation错误
- Android Stuido怎样查看快捷键冲突?
- java-对象的生命周期及AndroidUI卡顿
- easyui中方向键、tab键、回车键
- 既然有了点方法为啥还要用valueForKey
- 【学习笔记】NGUI中为Popup Menu添加点击事件响应