• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Redirect to a login page in another server

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, Ben. You are very helpful
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic