Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-05-14
4
Medium Priority
?
201 Views
Last Modified: 2010-04-01
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"...
0
Comment
Question by:InNoCenT_Ch1ld
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
fargo earned 2000 total points
ID: 16680295
Hi, In your case the servlet filter will best suit the need. For more information see here http://java.sun.com/products/servlet/Filters.html

Using servlet filter and keeping the mapping for all pages, one ensure that any request will definitely go thru servlet filter and there u can have the check for "id" or any other session identifier and then better forward to login page or destination page.
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 16680322
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?
0
 
LVL 11

Expert Comment

by:fargo
ID: 16680509
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.
0
 
LVL 3

Author Comment

by:InNoCenT_Ch1ld
ID: 16680558
tks.. i think it should be sufficient.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Machine Learning is one of the profound applications of AI and therefore, just like AI, it is surrounded by myths and fears. Check out these facts about ML that demystify the related myths.
The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question