• Post Reply Bookmark Topic Watch Topic
  • New Topic

Redirect to a login page in another server

 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to write a page to redirect requests not from a particular source. The source is an login page in another server to perform LDAP authentication. If the request was posted from anywhere else, the page would redirect it to the login page. The section of the code is listed below


Will cause a illegal state exception while:
will work fine.

My question is why? An yes, I know a better approach will be to use a front controller or a filter. Would any body have code for a filter like this ready (including the web.xml) for this simple task.

Thanks all for helping or attempt to help me in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because sendRedirect doesn't stop the execution of your JSP.


In this code block you will redirect if the referer is null but the page will continue to the if statement on line 7 which will return true.
This means that the JSP will attempt a second redirect and throw an illegal state exception.

Just put a return; statement directly under each sendRedirect and it should be fine.
 
Chit Ming Chong
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Ben. You are very helpful
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!