• Post Reply Bookmark Topic Watch Topic
  • New Topic

How make so a servlet captures all requests?  RSS feed

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bunch of jsp pages, but I don't want anyone to be able to type them in and go directly to them. I want them to only be accessible through my servlet. Do I have to map the servlet to every name of jsp page? how do i make all those requests go to the servlet?
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can, as you said, map all the requests through a servlet.
Or, if you use Struts, you can put all your pages under WEB-INF and link to them via actions. See http://www.husted.com/struts/catalog.html under the heading "Place all Java ServerPages below WEB-INF"
 
Pete Harris
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a word of warning. This will indeed work on tomcat, but if you decide to use another app server such as weblogic, it may fail. This is because weblogic won't serve files out of it's WEB-INF directory no matter how they are referenced.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that's "serving" files. If you only include or forward to those files, then they are still considered servlets to be invoked, and not served directly by the web server. Or am I wrong, and certain containers won't allow that at ALL. I don't see how, since servlets are in there and it has to work *somehow*.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that you could always include/forward to JSP pages contained underneath the WEB-INF directory. Okay, the Servlet spec says that they will not be served directly, but you should be able to access them through the RequestDispatcher.
Simon
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to mention - I wrote a chapter about web application architecture (model 1, model 2, J2EE patterns, etc) that might be relevant. You can download it from http://www.simongbrown.com/publications/proservlets.html.
Simon
[ February 11, 2003: Message edited by: Simon Brown ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!