Getting relative file url inside include, jsp file

I have a Main.jsp file located on the path of the absolute URL "Http://Mywebpage.com/Open/This/Folder/Main.jsp".

Inside Main.jsp there is jsp include:

<%@ include file="../../Top.jsp" %>

Now, on the Top.jsp page, I have other jsp and javascript instructions that reference the files:

<%@ taglib uri="emonogram.tld" prefix="em" %>
...
<script type="text/javascript" src="HL.js"></script>

emonogram.tld and HL.js are stored in the same directory as Top.jsp, that is, "http://Mywebpage.com/Open/".

I need Top.jsp to be flexible enough so that any file can link to it, no matter where it is in the directory tree. The problem here is that I am getting errors because the files specified in Top.jsp cannot be found. What for? The jsp include path will be the relative Main.jsp path. Thus, Top.jsp will fail because when I call emonogram.tld I want "http://Mywebpage.com/Open/emonogram.tld", but actually it is "http://Mywebpage.com /Open/This/Folder/emonogram.tld ".

I tried to consider some jsp options like getRequestURL, getServletPath, getRealPath and getContextPath, but these methods do not seem to return what I want.

, Top.jsp emonogram.tld HL.js, . , ; .


: BalusC, Tomcat 5.5. , web.xml . JSP 1.2 . ${} <% %>, make break, , . .

, "get...", , , .

getContextPath() /Open BOTH Top.jsp Main.jsp, Main.jsp /Open/This/Folder/. "emonogram.tld", , , , javascript.

.

Update2: , ; JSTL 1.2, JSP 1.2. Tomcat 5.5.28, JSP 2.0 JSTL 1.2.

, . , , . getContextPath() /Open/This/Folder/ Main.jsp /Open/ Top.jsp, /Open/ , . , , , .

+3
1

<script src> URL- ( ), JSP . -, script, -.

, URL-

http://Mywebpage.com/Open/This/Folder/Main.jsp

JS

http://Mywebpage.com/HL.js

<script type="text/javascript" src="/HL.js"></script>

.

, webapp , , /Open () , JS

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

URL- HttpServletRequest#getContextPath().

<script type="text/javascript" src="${pageContext.request.contextPath}/HL.js"></script>

: ( , , )

<script type="text/javascript" src="/Open/HL.js"></script>

. :


: , , TLD, . TLD /WEB-INF uri="/WEB-INF/filename.tld".

+13

All Articles