How specify path to .JSP file for request.getRequestDispatcher()?

前端 未结 1 528
有刺的猬
有刺的猬 2021-01-23 03:12

I am confused about the meaning of request.getContextPath(). My file layout is as follows:

MyServer/WebContent:
    /Resources/MyImage.jpg
    /Resources/Script         


        
相关标签:
1条回答
  • 2021-01-23 04:10

    The RequestDispatcher operates already relative to the current web application context. You don't need to prepend the context path.

    Why it is required for JS/CSS/image/etc resources which are linked in HTML is simply because it's the webbrowser who has got to download them by a proper URL path. A common starters mistake is that they think that it's the webserver who has got to auto-include them by a local disk file system path somehow. This is thus not true. It has really to be an URL, like the one as you enter in browser's address bar.

    See also:

    • Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
    0 讨论(0)
提交回复
热议问题