问题
In reference to my older unanswered question, I have a further error / problem that is partially related to it.
generic linking, variables and paths in jsp

When I include my header.jsp like this:
<%@include file="/WEB-INF/view/jsp/common/header.jsp" %>
It works fine.
But does not if I do it like this:
<%@include file="${pageContext.request.contextPath}/view/jsp/common/header.jsp" %>
Error:
HTTP Status 500 - /WEB-INF/view/jsp/common/login/login.jsp (line: 8, column: 1) File "${pageContext.request.contextPath}/view/jsp/common/header.jsp" not found
The above with ${} is a proper way and thats what I had been doing in the past until I started using spring and spring security.
But I dont think its a problem of spring or spring security.
I really cant understand why WEB-INF
has a weightage and
How can I make my links generic (ref my old stated question)
回答1:
Actually, it's not the proper way in this case. The context path is not used for creating paths within the internals of your app, as in this case. Instead, it is used to generate URLs within the view layer, such as links, form URLs, and etc.
In this case, the following is correct:
<%@include file="/WEB-INF/view/jsp/common/header.jsp" %>
The include line above is referring to a resource that is packaged inside your war file. How would the context path, which is configured at the servlet container, have anything to do with the location of something packaged inside your war?
To recap, you only need to use ${pageContext.request.contextPath}
to prefix URLs that are going to be placed in output to the client.
来源:https://stackoverflow.com/questions/18038955/pagecontext-request-contextpath-and-generic-linking