aspose file tools*
The moose likes Servlets and the fly likes Deny JSP straight access but use them as forwards. How? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Deny JSP straight access but use them as forwards. How?" Watch "Deny JSP straight access but use them as forwards. How?" New topic
Author

Deny JSP straight access but use them as forwards. How?

Grigory O. Ptashko
Greenhorn

Joined: Jan 26, 2006
Posts: 16
Hello.

I need to do the following scheme: I want all the URLs to be handled by one servlet, e.g /one or /one/two or /one/two/three.do to be handled by only one servlet, say MainServlet. And I want to deny access to JSPs but use them only as forwards from my servlet. E.g. when a user types http://myserver.com/some.jsp, he/she get 404 not found, or forbidden, whatever. But he/she must not straight access any JSP.

How must I configure my webapp?

Thank you.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You can put them under the WEB-INF directory which can't be accessed directly from a browser.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

I place all of my JSPs -- except those that must be able to be accessed directly, usually very few -- in a folder structure rooted at WEB-INF/pages.
[ January 26, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Grigory O. Ptashko
Greenhorn

Joined: Jan 26, 2006
Posts: 16
Oh, that's a great idea. I've just tried it out and it worked
I want to ask whether it is a normal practice to like that but I saw the second reply and changed my mind

Thanks guys.

But still, what <url-mapping> should I specify so that all the requests to my server are handled only by MainServlet?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Originally posted by Grigory O. Ptashko:

But still, what <url-mapping> should I specify so that all the requests to my server are handled only by MainServlet?


Actually you probably do not want all requests to be routed to the front controller unless the front controller servlet is going to handle all requests including image file, script files and style sheets.
[ January 26, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Originally posted by Satou kurinosuke:
<url-pattern>/*</url-pattern>


Like I said, that will capture all requests. Probably not what you want to do.

More common: something like /someprefix/*.
Grigory O. Ptashko
Greenhorn

Joined: Jan 26, 2006
Posts: 16
Bear,

yes, that's what I need. I'll make it with some prefix. Thanks for your comment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deny JSP straight access but use them as forwards. How?