How come request.getPathInfo() in service method returns null?

前端 未结 2 620
终归单人心
终归单人心 2020-12-17 09:57

I wrote Front Controller Pattern and ran the test. Somehow request.getPathInfo() is returning null when it should return the path info.

1. HTML that calls se

相关标签:
2条回答
  • 2020-12-17 10:35

    @Vivien is correct. You'd like to use HttpServletRequest#getServletPath() instead (sorry, I overlooked that bit while writing the answer which you undoubtely was reading, I've updated the answer).

    To clarify: getPathInfo() does not include servlet path as definied in web.xml (only the path thereafter) and getServletPath() basically returns only the servlet path as definied in web.xml (and thus not the path thereafter). If the url pattern contains a wildcard, particularly that part is included.

    0 讨论(0)
  • 2020-12-17 10:40

    According to the Javadoc:

    Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string. This method returns null if there was no extra path information.

    You don't have any path info when using a prefixed mapping (*.do, in your case).

    0 讨论(0)
提交回复
热议问题