2010-03-30 67 views

回答

1

HttpServletRequest#getPathInfo()正是为了这个目的。

String path = request.getPathInfo(); 

就是这样。不需要像这里的另一个答案中所建议的那样从它中抽取servlet路径。另请参阅我的回答在您的other question

1

在HttpServlet的doGet或doPost方法中,您可以使用HttpServletRequest对象的getRequestURI方法来检索URL的路径部分。因为它听起来像你也想砍掉的是映射到的serlvet可以使用getServletPath方法路径的部分,然后做这样的事情:

String path = request.getRequestURI(); 
if(path.startsWith(request.getServletPath())) { 
    path = path.substring(request.getServletPath().length()); 
} 
相关问题