2

This is the structure: (they're in the same directory!)

Directory
|-view.jsp
|-stylesheet.css

When I do <link href="stylesheet.css" rel="stylesheet" media="screen"> The .css file does not get referenced correctly, i.e. I have no idea what path to set to get to it (if put as a URL in the browser, I get a 404).

I guess it gets translated as http://localhost:8080/myApp/stylesheet.css and then there is no mapping defined for it. Logging says:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/myApp/stylesheet.css] in DispatcherServlet with name 'appServlet'

It should work like this, shouldn't it? For example, this works:

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

include.jsp is in the same folder as well.

Bloke
  • 2,229
  • 3
  • 22
  • 27

1 Answers1

2

JSP views and other resources stored under WEB-INF/ are not directly accessible to the end-user, they are web application's private resources and the server doesn't expose them. You'll have to place any public resources one level above WEB-INF/, for example:

webapp/
|-- style/
|     stylesheet.css
|-- images/
|     image1.png
|     image2.png
|-- html/
|     index.html
+- WEB-INF/
  +-- jsp/
        view.jsp
        include.jsp
kryger
  • 12,906
  • 8
  • 44
  • 65
  • So how does a JSP (not an end-user) access a resource (a CSS), specifically, what path should *webapp/WEB-INF/jsp/view.jsp* set as *href* to reference this *webapp/style/stylesheet.css*? – Bloke May 11 '13 at 20:07
  • 1
    @Bloke JSP does not access the CSS, the user's browser does it. And browser can't find resource under WEB-INF – Patison May 11 '13 at 22:39
  • The JSP template gets rendered to plain HTML and exposed under some publicly accessible URL; you can either use an absolute path to the CSS (i.e. "/myApp/style/stylesheet.css") or a relative path (depends on what URL the page is mapped to; if it's in the webapp's root, like `/myApp/index.html`, it would be "style/stylesheet.css", if it's on a different level, for example `/myApp/subdir/page.html`, it would be "../style/stylesheet.css") – kryger May 11 '13 at 22:40
  • how you put in index.html.if want to navigate to view.jsp in web-inf folder? – jdev Oct 16 '13 at 13:16