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

前端 未结 2 631
终归单人心
终归单人心 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.

提交回复
热议问题