How to redirect to login page if not logged in
hi,
i have a tomcat web application and it is working properly. i have only javascript and jsp but if user types any url of any jsp without login its displaying that page for that i written the code like this in jsp.... but its not working........ so any one please help me...........
the code is
<% if(null == session.getAttribute("username")){
response.sendRedirect("./jsp/logout.jsp");
}else { %>
<a href="../jsp/useradmin.jsp?">Add User </a> <%} %>
this is not redirecting to login page if i entered url useradmin page directly without login. any one please tell me sollution..
Re: How to redirect to login page if not logged in
Have you tried printing the value returned by session.getAttribute("username") to the screen to see what it is returning.
Re: How to redirect to login page if not logged in
I know in .net how would this happen but dnt know in java.
Re: How to redirect to login page if not logged in
have you tried spring security ? it has such feature out of box.