Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Is it good Idea to place css and js resources outside the WEB-INF folder?

 
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am working on a web application where I have placed all my JSP file inside the WEB-INF folder

but I have placed my CSS and JS file outside the WEB-INF folder.

problem is that suppose my css is located in some directory like

"WebApplicationRoot/css/myHome.css"

and when I try to access it like this using tag library
<link rel="stylesheet" href="<c:url value="/css/main.css"/>" type="text/css"/>

and when I place those css file like this

"WebApplicationRoot/WEB-INF/css/myHome.css"

and when I try to access it like this using tag library
<link rel="stylesheet" href="<c:url value="/WEB-INF/css/main.css"/>" type="text/css"/>

then my css file is not loaded in my web browser

so what should I do?

Thanks
 
Ranch Hand
Posts: 56
4
Mac OS X IntelliJ IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. A very good idea! :)

Resources inside WEB-INF are protected to be not accessible directly from the client -
therefore it would contains server resources like JSPs.
static content however will directly be downloaded from the client browser, so it must not be inside of WEB-INF.
 
Marshal
Posts: 67446
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resources such as images, stylesheets and scripts must never be placed inside WEB-INF as the browser must address those directly.

JSPs on the other hand should go into WEB-INF so that they cannot be directly addressed without going through their page controllers.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
Bear
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic