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的博客。

这时再去数据库里查相应的数据就好。

最新文章

  1. Java transient 关键字
  2. PhpStorm破解教程
  3. C# 装箱和拆箱的简单理解
  4. SQL SERVER触发器游标小记
  5. Linux 信号
  6. nagios&ndash;配置文件
  7. android 服务service开启和关闭
  8. android webview点击返回键回到上一个html
  9. 控制台命令行API
  10. web前端效率提升之禁用缓存-遁地龙卷风
  11. js中时间戳与日期格式的相互转换
  12. vue中的一些知识点--多看文档
  13. webpack配置(入口出口)
  14. centos下常用文件管理命令
  15. JS 自己实现Map
  16. 去掉 input type=&quot;number&quot; 在浏览器中遗留的图标样式
  17. Zookeeper笔记之使用zk实现集群选主
  18. The last access date is not changed even after reading the file on Windows 7
  19. TF400511: Your team has not defined any iterations to use as sprints
  20. HDU 4696 Answers (2013多校10,1001题 )

热门文章

  1. encodeURI() 函数概述
  2. java中通过配置文件的方式(Jedis驱动)使用Redis
  3. Introduction to Mathematical Thinking - Week 3
  4. Ubuntu 系统下可以做什么?
  5. 【题解】CF611H New Year and Forgotten Tree
  6. 使用PLSQL Developer和DbVisualizer、SQLDBx查询oracle数据库时出现乱码
  7. Android Integer.parseInt java.lang.NumberFormatException: Invalid int解决方法
  8. HTML+CSS理解
  9. Java底层代码实现多文件读取和写入
  10. jstl-functions标签