servlet中的几个路径有关的方法

在编写JSP/Servlet应用时常常需要从传入的链接中提取一些信息。HttpServletRequest提供了多个方法,这些方法之间容易混淆。总结并举例如下,希望能对大家有所帮助。

举例:http://localhost:7001/myservlet/somepath/test?someparam=somevalue
request.getPathInfo():返回/somepath/test
request.getRequestURL():返回http://localhost:7001/myservlet/somepath/test
request.getRequestURI():返回/myservlet/somepath/test
request.getServletPath():返回/myservlet
request.getQueryString():返回someparam=somevalue

posted @ 2011-01-23 23:34  琥珀光  阅读(196)  评论(0编辑  收藏  举报