Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Public folder in JavaEE website

 
Martin Bechtle
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody.
I started using java for web apps a few months ago and i still have much to learn. I have one simple question to which i found no answer on the internet.

We all know the directory structure of a webapp

/
/WEB-INF
/WEB-INF/lib
/WEB-INF/classes

Files in the root directory are available via HTTP to the end user. But it would be such a mess to put DOZENS of images and other stuff just in one directory!
Isn't there a way to tell the servlet container to have more public dirs? Besides, many javascript applications (like TinyMCE editor) have their own directory structure and many .js files would end not being in a public folder.

Any suggestions?

Thank you in advance.
 
Tim Moores
Bartender
Posts: 2789
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create directories in the root directory as you please: /images, /css, /js, ... They will all be publicly accessible.
 
Martin Bechtle
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, excellent!
And what about making them inaccessible for end user? What's the best practice? CHMOD them, configure some XML on the server or placing them in WEB-INF/...?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any resource you do not want to be directly accessible via URL (JSPs for example, which should only be accessed via their page controllers) can be placed under WEB-INF.
 
Martin Bechtle
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All clear then. Thank you for your precious replies.
 
Miku Ranjan
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I put my jsp content inside the WEB-INF how can access that page from servlet to redirect to that jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miku Ranjan wrote:Hi,
If I put my jsp content inside the WEB-INF how can access that page from servlet to redirect to that jsp.

You don't. All access to the JSP should be through its page controller. Please read this article for more information.
 
Miku Ranjan
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,
Thank for the article but which part of the article I should look for my answer.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the whole thing. Just reading a small part will be of little use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic