Link to home
Start Free TrialLog in
Avatar of InNoCenT_Ch1ld
InNoCenT_Ch1ld

asked on

The "right" or "normal" ways to check if a user is logined already and show different pages...

Hi, currently in my jsp, i use the below "ways" to check if the user is loginned, if he is, then it will show the jsp page, else, it will be FORWARDed to login.jsp:

<!-- Check for login status -->
    <jsp:useBean id="loginstatus" class="data.LoginStatus" scope="session"/>
<%
    if(session.getAttribute("id") == null || session.getAttribute("id").equals("")){
        loginstatus.setStatusMsg("You must login first dude.");
%>
        <jsp:forward page="login.jsp"/>
<%
    }
%>


but after reading some reference books, they all said that DO NOT use forward, but use RequestDispatcher.forward instead. Then I come out with an idea of checking if the user is loginned in my servlet, if yes, then use requestdispatcher's forward to the targetted jsp, else, to login page....
but after another careful thought, i realize that the user can directly enter the link to my jsp page (by passing the servlet, eg: http://host/level1/level2/view_critical_data.jsp).. means they still can view the page even if they aren;t logined!

so, please.. anyone or every experts here, kindly show me the real/professional/correct ways in achieving my "goal"...
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of InNoCenT_Ch1ld
InNoCenT_Ch1ld

ASKER

tks for the respond, fargo ;-)
but it seems kind of "complicated" to use for a new user like me...

do u use it before? any chance i can get a crash course from you or anyone/ any website?
Following two links may help you.
http://javaboutique.internet.com/tutorials/Servlet_Filters/
http://www.onjava.com/pub/a/onjava/2003/11/19/filters.html

I do use servlet filter for many purposes. I have no time at the moment as i m busy with my projects. Please try to follow the above two links and let us know if u face any problems.
tks.. i think it should be sufficient.