It's not a secret anymore!*
The moose likes JSP and the fly likes Login bean help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Login bean help" Watch "Login bean help" New topic

Login bean help

Dean Reedy
Ranch Hand

Joined: Sep 10, 2001
Posts: 89
I have seen talk about using beans for logging into a website and here is what I have pieced together so far. Questions at the end!
public class UserLogin {
private boolean loggedIn = false;
public UserLogin() { }
public void setLogin(String user, String pass) {
// Validate login correct here and set to true or false
public boolean validUser() {
return loggedIn;
settup bean after login.html
// loaded from the login.jsp page via a form.
<%@ page import = "UserLogin" %>
<jsp:useBean id="c" scope="session" class="UserLogin">
<% c.setLogin(request.getParameter("username"),request.getParameter("password") ; %>

Code on everypage to verify they user has logged in
<jsp:useBean id="c" class="UserLogin" scope="session" />
<% if (!c.validUser()) response.sendRedirect("login.jsp"); %>

Is this code going to run, or is there something I am missing.
What do I need to added to the web.xml file for Tomcat 4 to run this.
Any guidance or examples or helpful websites would be great. Thanks!!!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Login bean help
Similar Threads
some problem with java beans scope attribute?
Using window.location.href
Passing data between beans
Setting HttpSession Attribute Not Working (Struts)
jsp bean problem, equal not working on strings