%@ page import="java.util.*" %> <% boolean gotInput = false, gotSession = false, authenticated = false, invalid = false; gotInput = (request.getParameter("username") != null); gotSession = (session.getAttribute("username") != null); String userNameFormInput = request.getParameter("username"); String password = request.getParameter("password"); String msg = ""; if (null == session.getAttribute("username") && gotInput) { // no session if (!userNameFormInput.equals("JoeBobHester")) // wrong user invalid = true; if (!password.equals("340829th")) // wrong password invalid = true; if (!invalid) { authenticated = true; session.setAttribute("username", request.getParameter("username") ); session.setMaxInactiveInterval(86400); } else { authenticated = false; msg = "Invalid login, please try again."; } } else if (gotSession) { authenticated = true; // existing session } else { // no session, no input--put up form authenticated = false; } if (authenticated) response.sendRedirect("menu.jsp"); /* if ( null == session.getAttribute("username") ) { // no session if (request.getParameter("username") != null) // got username if (request.getParameter("username").equals("smadmin")) // check username validity if (request.getParameter("password") != null) // got password if (request.getParameter("password").equals("sojamcrsp")) { // check password validity authenticated = true; session.setAttribute("username", request.getParameter("username") ); session.setMaxInactiveInterval(86400); response.sendRedirect("menu.jsp"); } } else { authenticated = true; // session already established } */ %>