aspose file tools*
The moose likes Servlets and the fly likes Throwing server errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Throwing server errors" Watch "Throwing server errors" New topic
Author

Throwing server errors

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi guys,

Is there anyway of throwing a server error (like a 401 Unauthorized) in a servlet if the user's session has expired ?
Vijay Dharap
Ranch Hand

Joined: Mar 18, 2004
Posts: 32
shaf maff wrote:Hi guys,

Is there anyway of throwing a server error (like a 401 Unauthorized) in a servlet if the user's session has expired ?


Hello Again!

I think the better way to do that is using Filters.
Define a filter on /* to see if the hit is for say.. Login.jsp / LoginsServlet or not...
As long as request is not for such "unprotected" resources, check if session exists / a particular variable exists in session..
If no session exist, throw back 401 Unauthorized (response.sendError() ). Or better still forward the user to your Login action / jsp.
If session exists, just let filter call doChain() for next filter in chain.
If the request is for unprotected resources, you can again let doChain get called.

Hope that helps..


Vijay dharap,
<a href="http://dharapvj.wordpress.com" rel="nofollow">Blog</a>
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Check the user session. if it is null then redirect the particular user to unathorized page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Throwing server errors
 
Similar Threads
Comet and PushServlet
exception starting weblogic
this keyword inside run() method
rmi: Connection reset
setAutoCommit - URGENT.....