This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Servlets and the fly likes Preventing direct access to an HTML page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Preventing direct access to an HTML page" Watch "Preventing direct access to an HTML page" New topic
Author

Preventing direct access to an HTML page

Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Hi
I have a requirement where I need to redirect to an HTML page from a servlet. The HTML page should not be directly accessible otherwise. How can I achieve this? Please note, using JSP instead of HTML is not an option.


Thanks and Regards
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 606

Put your html file inside the WEB-INF folder of your web application. That's the only way (I know of) that you can prevent the user from directly accessing a web resource on your server!

Of course it also means you cannot use a response.redirect() to access the web page and would have to use a forward() instead. In fact I don't think there is any way you can hide a resource to which you redirect since request for any redirected resource comes ultimately from the browser itself.

Just out of curiosity - why can't you use jsp instead of html? Good pattern would dictate that all your files be '.jsp' anyways?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Thanks Sam. Let me clarify the requirement a bit. Actually its a SWF (Flash player file) to which I need to move from servlet and not HTML. I said HTML in the question, to keep it familiar and simple.
 
 
subject: Preventing direct access to an HTML page