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的博客。
这时再去数据库里查相应的数据就好。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/turkeyzhou/archive/2008/11/10/3270289.aspx
分享到:
相关推荐
The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...
jsp探针ceshi.jsp ; charset=gb2312" %> class LfSpy { boolean supportHibernate = false; boolean supportJNDI = false;...boolean supportJavaxSql = false;...private final String linuxParseMacAddress(String ...
这份文档以及刚才提及的Javadoc格式的文档都描述了这两个软件包,Javadoc格式的文档还描述了你应该如何使用这两个软件包中的所有方法。 有关规范 你也许对下面的这些Internet规范感兴趣,这些规范将直接影响到...
主要介绍了yii2.0实现pathinfo的形式访问的配置方法的相关资料,需要的朋友可以参考下
很简单的方法获得USB的序列号 Option Explicit Private Declare Function GetVolumeInformation Lib "kernel32.dll" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As ...
挑战EASE解决方案带有c ++挑战解决方案的存储库。 在Visual Studio Community 2019中开发。可以在文件Challenge.pdf中找到挑战的描述。Proyect结构该保护器分为4个文件Challende_EASE_... GetPathInfo:计算坡度并保
路径 给定和浏览器的字符串路径的对象值检索工具。 什么是pathval? Pathval是一个模块,您可以使用该模块为给定的String路径检索或设置Object的属性。... getPathInfo(object, path) -返回一个对象,其中info
介绍 之前在邮政实习时,leader让我阅读tomcat的...当你请求ManagerServlet时,它会检查getPathInfo()返回的值以及相关的查询参数,以确定被请求的操作。它支持以下操作和参数(从servlet路径开始): 请求路径 描述