0

I have website project .user can log in to use it at the home page
now the problem is if any user write URL for any other page without login it will show him the page I need to ensure that any user visit other page have already logged in AT THE HOME PAGE
I USED JSP MYSQL JS CSS HTML

2
Contributors
1
Reply
12
Views
2 Years
Discussion Span
Last Post by milil
0

You can do it using C taglib library.
C taglib library give you if, when, for, while loops so you can use it in .jsp pages so you will just need if in C taglib it is called: choose
To use C taglib just put this in top of your page:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

In you servlet where you check login of user you can add field to session to set userLogedIn = true;

boolean userLogedIn = true;
request.getSession().setAttribute("userLogedIn", userLogedIn);

Then on every page you will have something like this:

<c:choose>
    <c:when test="${userLogedIn}">
    // HTML YOU WANT TO SHOW WHEN USER IS LOGED IN!!!
    </c:when>
    <c:otherwise>
        PLEASE LOGIN!!!
    </c:otherwise>

</c:choose>

When you logout just delete this from session and that is it.
Every user will have thier own session so you don't need to wory about anything...
You can find a lot of examples on this link.
I hope this will help you. If you have any questions feel free to ask.
Regards, Mike.

Edited by milil

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.