0

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!

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
williamsandonz
  • 15,864
  • 23
  • 100
  • 186
  • 3
    possible duplicate of [Servlets - Browser can't access css, images when doing a forward to a JSP?](http://stackoverflow.com/questions/3655316/servlets-browser-cant-access-css-images-when-doing-a-forward-to-a-jsp/3658735#3658735) and [How to use relative paths without including the context root name?](http://stackoverflow.com/questions/4764405/how-to-use-relative-paths-without-including-the-context-root-name/4764586#4764586) – BalusC Nov 08 '11 at 23:02

2 Answers2

2

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" %>
Ken Russell
  • 2,348
  • 5
  • 24
  • 39
2

Yes, use <c:url value="/css/file1.css" /> - this will append the context.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140