Search code examples
eclipsejsptomcatservletscontextpath

How to set relative URL in servlet jsp


I'm jumping into an existing JSP project, using eclipse spring, tomcat 6.

Our project currently has the URL: http:localhost/path1 as its base.

In my index.jsp, when I try to reference .css & .js using: "/css/my.css"

It doesn't append the "/path1" before it, how do I set it up to automatically add that?

And I can't use a variables as I want to these fixed paths inside my .css file to reference images.

I don't want to explicitly type it in as that "path1" will change later.

Thanks!


Solution

  • Context path need to be included at the beginning of the url. If you don't want to hardcode the context path, you may use the following

    <%@ include file="${pageContext.request.contextPath}/css/My.css" %>