request.getPathInfo();
2015-10-11 22:44
337 查看
request.getPathInfo();
这个方法返回请求的实际URL相对于请求的serlvet的url的路径。(个人理解。)
比如,有一个Servlet的映射是这样配置的:
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/servlet/test/*</url-pattern>
</servlet-mapping>
为servlet配置的访问路径是:/servlet/test/*
我只要访问: http://localhost:8080/dwr/servlet/test/这里可以是任何东西
就可以访问那个servlet. dwr 是项目的名字
比如,我用这个 URL 来访问它:
http://localhost:8080/dwr/servlet/test/joejoe1991/a.html
这个实际的URL,相对于那个servlet 的url ("/servlet/test/*")的路径是:
/joejoe1991/a.html
所以 request.getPathInfo() 方法返回的就是:
"/joejoe1991/a.html"
如果你的URL里有查询字符串,getPathInfo() 方法并不返回这些查询字符串。
例如:
http://localhost:8080/dwr/servlet/test/joejoe1991/a.html?name=test
getPathInfo() 返回的仍然是:
"/joejoe1991/a.html" ,而并不包括后面的"?name=test"
我们可以利用这个方法去做类似于多用户博客系统的那种URL。
都是http://www.xxx.com/blog/ 开头
后面跟的是用户名,
比如我要访问joejoe1991的博客:
http://www.xxx.com/blog/joejoe1991
这个joejoe1991并不是一个真实存在的目录。
建一个servlet,配置路径为:/blog/*
然后在这个servlet里调用request.getPathInfo() 方法。
比如:http://www.xxx.com/blog/jjx
那request.getPathInfo() 方法返回的就是jjx ,表示要访问jjx的博客。
这时再去数据库里查相应的数据就好。
这个方法返回请求的实际URL相对于请求的serlvet的url的路径。(个人理解。)
比如,有一个Servlet的映射是这样配置的:
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/servlet/test/*</url-pattern>
</servlet-mapping>
为servlet配置的访问路径是:/servlet/test/*
我只要访问: http://localhost:8080/dwr/servlet/test/这里可以是任何东西
就可以访问那个servlet. dwr 是项目的名字
比如,我用这个 URL 来访问它:
http://localhost:8080/dwr/servlet/test/joejoe1991/a.html
这个实际的URL,相对于那个servlet 的url ("/servlet/test/*")的路径是:
/joejoe1991/a.html
所以 request.getPathInfo() 方法返回的就是:
"/joejoe1991/a.html"
如果你的URL里有查询字符串,getPathInfo() 方法并不返回这些查询字符串。
例如:
http://localhost:8080/dwr/servlet/test/joejoe1991/a.html?name=test
getPathInfo() 返回的仍然是:
"/joejoe1991/a.html" ,而并不包括后面的"?name=test"
我们可以利用这个方法去做类似于多用户博客系统的那种URL。
都是http://www.xxx.com/blog/ 开头
后面跟的是用户名,
比如我要访问joejoe1991的博客:
http://www.xxx.com/blog/joejoe1991
这个joejoe1991并不是一个真实存在的目录。
建一个servlet,配置路径为:/blog/*
然后在这个servlet里调用request.getPathInfo() 方法。
比如:http://www.xxx.com/blog/jjx
那request.getPathInfo() 方法返回的就是jjx ,表示要访问jjx的博客。
这时再去数据库里查相应的数据就好。
相关文章推荐
- Twenty Questions
- EasyUI - Panel 面板控件
- hdu 5496 Beauty of Sequence(高效)
- UIKit
- 有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?
- UI基础总结第一天
- 【IOS 开发学习总结-OC-43】★ios开发——UIButton(按钮)与 UISwitch(开关按钮)
- UI设计十戒--设计师的艺术
- UI交互设计体验--未来声控之路?
- UIButton 文字显示位置设置 字体的大小设置 字体的颜色设置 注意事项
- 移动界面UI颜色设计
- iOS开发- UICollectionView详解+实例
- 产品UI设计排版的四个基本原则
- Android UI学习系列-ActionBar你最熟悉却又陌生的她(上篇)
- some commands for mount equipment
- java.lang.SecurityException: Need BLUETOOTH ADMIN permission: Neither user 10047 nor current process
- iOS:图像选取器控制器控件UIImagePickerController的详解
- String StringBuffer StringBuilder之间的区别
- 交互设计菜鸟稳健入门之路
- UI设计师产品构思过程需要有一个系统思维方向