views:

97

answers:

2

Hello,

My application use stardard MVC pattern with jsp and servlets. I like to redirect to login page when the user clicks a link after session expire. Same application is used for many countries, so i give a country code with the login url. So simple redirecting to login page is not possible. How can i redirect to my web application root? It looks like this... www.mysite.com/LoginServlet?country='EUF'

Please help.

Thanks...

A: 

You could use a servlet filter that sends a redirect to the user. If the session is expired the filter redirects the user to your login page.

deamon
but i need the login page parameters with the login page. From where i'll get that?
coder247
The filter can redirect to an arbitrary URL, so you can add whatever parameter you want.
deamon
+1  A: 

Assuming form based authentication you would add something like that into you web.xml this requires the user be authenticated before any other pages are accessible

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Secured</web-resource-name>
        <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>            
    </auth-constraint>
</security-constraint>

<security-role>
    <role-name>admin</role-name>
</security-role>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>Form-Based Authentication</realm-name>
    <form-login-config>
        <form-login-page>/Login.jsp</form-login-page>
        <form-error-page>/Login.jsp</form-error-page>
    </form-login-config>
</login-config>
stacker