开发者

redict to login after session expire

开发者 https://www.devze.com 2022-12-18 04:08 出处:网络
My application use stardard MVC pattern with jsp and servlets. I like to redirect to login page when the user clicks a link after ses开发者_JAVA百科sion expire. Same application is used for many count

My application use stardard MVC pattern with jsp and servlets. I like to redirect to login page when the user clicks a link after ses开发者_JAVA百科sion 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...


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消