1

i'm trying to to move all my stuff (jsp pages, CSS, images) in the WEB-INF folder. But now, i can't reach, for example, my CSS with the "usual" code

<link rel="stylesheet" type="text/css" href="CSS/Style.css" >   

Under WEB-INF i have this kind of structure

enter image description here

How can i reach from a JSP page (inside the JSP folder) a CSS file (inside the CSS folder)?

DO i have to use getServletContext() in every html page?

MDP
  • 4,177
  • 21
  • 63
  • 119
  • Can we know why do you want to move your resources like CSS and/or images to WEB-INF? – Pshemo Jul 11 '14 at 13:47
  • WEB-INF is a folder that won't be accessed from outside the server. The only files I would move to WEB-INF are jsp fragments - jsp pages that are not intended to be viewable by themselves but only included on other pages. – zbig Jul 11 '14 at 14:05

2 Answers2

1

Do not move HTML resources into WEB-INF, the entire point of that folder is that the server will not directly serve files from there. If you really, really want to, you can but then you must write a controller servlet to serve those static files, don't forget to set the content-type appropriately. Also, you won't be able to access them as "/WEB-INF/css/blah.css" because the server won't serve the folder. So it would be something like "/myServlet?resource=css/blash.css".

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
1

If you are using Spring, you can put all your files (CSS,JS,...) in the folder :

src/main/webapp/resources (create if not exists).

And then in your servlet config xml :

<mvc:resources mapping="/resources/**" location="/resources/" />

MrLo
  • 182
  • 3