1

In jsp page am creating login page, it contains username and password fields, am storing username in session, and am validating fields, if everything correct it will be redirect to Home page (home.jsp).

This all process happening successfully.

My question is, when i type url for login page, it come with localhost:2500/shashi/login.jsp url.

When it is redirect to home page, the url will be localhost:2500/shashi/home.jsp. its correct.

But suppose after log in, if session is not expired,

if i type localhost:2500/shashi/login.jsp login url, it should redirect to home i.e localhost:2500/shashi/home.jsp

How do i achieve this? java is server side code. web-server jetty

  • Check in your servlet if user object present in session redirect user to `home.jsp` page.Hope you are doing session invalidate when user logout . – Subodh Joshi Aug 21 '15 at 06:43
  • 2
    possible duplicate of [How to redirect to another page when already authenticated user accesses login page](http://stackoverflow.com/questions/8239925/how-to-redirect-to-another-page-when-already-authenticated-user-accesses-login-p) – Himanshu Tyagi Aug 21 '15 at 06:46

2 Answers2

0
<%  if(request.getSession(false).getAttribute("username") == null) {

        %>
        <script type="text/javascript">
            window.location="${pageContext.request.contextPath}/home";
        </script>
        <%          
    }
%>

Try this code insert at your header.jsp file, if not present header file then put in jsp file

shas
  • 703
  • 2
  • 8
  • 31
zoomba
  • 1
  • 3
0

I think about something simple like this:

if(request.getSession(false).getAttribute("username") == null){
    response.sendRedirect("/home.jsp");
}
uniking
  • 212
  • 2
  • 16