• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should we put JSP in WEB-INF

 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw many sample applications given by books do not put their JSPs inside the WEB-INF directory. But, I am wondering why! If we are using MVC, we only want the client to directly access our servlets but not the JSPs. Putting JSPs above WEB-INF means exposing them to the client.

Would there be any other considerations in deciding where to place the JSPs?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's pretty simple and straight-forward. If you want the JSP to be directly addressable put it outside WEB-INF. If you do not want it to be, put it inside WEB-INF.

My apps generally have an index.jsp at the root which redirects them to the controller for the home page. All other JSPs, sometimes with the exception of error pages, are hidden behind WEB-INF so that they can only be displayed by going through the appropriate controller/action.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, some experts (including author of Struts in Action here:
http://www.coderanch.com/t/46104/Struts/Struts-Modules-jsps-under-WEB

) do not favour putting JSP inside WEB-INF. I dare not challenge the authority. But just want to know what are the pros and cons of each approach.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To each, of course. Everyone is free to decide what is best for their own application.

However, I find the "some containers do not support it" reasoning rather specious. If you are not being forced to use a broken container, why cripple your application structure with provisions for a container that doesn't work right? One might argue that it limits the portability of the app, but why would you migrate from a container that works to one that doesn't?

And I competely do not understand the assertion that using Struts-like actions hides anything. Whether the controller execution unit is a servlet or an "action" has no bearing whatsoever on the addressability of the JSPs.

By the way, that thread is also 3 years old. Times and accepted practices change.

I dare not challenge the authority.


There are differing opionions among "authorities". Do you not think that it'd be best to solicit such opinions -- as indeed you are doing now -- and then make up your own mind as to which suits you and your app best?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic