Retrieving relative url path of file inside a include file, jsp

后端 未结 1 1988
再見小時候
再見小時候 2021-01-03 10:59

I have a file called Main.jsp, located at the absolute url path of \"http://Mywebpage.com/Open/This/Folder/Main.jsp\".

Inside Main.jsp, there is a jsp include:

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 11:31

    The

    The leading slash will make it relative to the domain root.

    However, if your webapp is not deployed on the domain root per se, but on a context path, such as /Open in your (oversimplified) example, and your JS file is actually located in

    http://Mywebpage.com/Open/HL.js

    then you need to prepend the URL with HttpServletRequest#getContextPath().

    
    

    This will end up as (rightclick page in browser, do View Source to see it)

    
    

    See also:

    • How to use relative paths without including the context root name?
    • Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP

    Update: as per your update, please note that this does not apply on TLD files since they are been resolved on the server side. Normally, you should drop TLD files in /WEB-INF folder and reference it by uri="/WEB-INF/filename.tld".

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