Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Throwing server errors

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the user session. if it is null then redirect the particular user to unathorized page
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic