// THIS VERSION IS FOR DEMO ONLY, NOT THE ONE I USE. /** ***************************************************************** loginDemo.java SWE 432 Student Information @author Jeff Offutt @version 1.0 (2/21/2004) @version 1.1 (8/24/2007) Upsorn Praphamontripong Update variables to run on Hermes (apps-it821.ite.gmu.edu) Establishes a login using a servlet session. IDs are hardcoded. doGet() prints the login screen. doPost() checks an ID/password and sets the session info. ********************************************************************* INSTALLATION INSTRUCTIONS 1) Modify StudInfoSysDemo.java (Changes marked there) 2) Modify loginDemo.java Change the following global variables: private static String LoginServlet = "http://ise.gmu.edu:8080/offutt/servlet/StudInfoDemo.loginDemo"; // ise private static String JSPLoc = "http://ise.gmu.edu:8080/offutt/jsp/"; // ise public static String classWebSiteURL = "http://www.ise.gmu.edu/~offutt/classes/Demo/"; public static String FileName = "/home/faculty/ofut/public_html/DATA/Demo-info-S06.xml"; // ise Also change the hard-coded passwords (feel free to laugh) in doPost(): if ((demoUserID.equals ("xxx") && demoPassWord.equals ("xxx")) || (demoUserID.equals ("xxx") && demoPassWord.equals ("xxx")) ) 2) Compille .java classes 3) Move .class files to ~/j2ee/servlets/StudInfoDemo 4) Copy .jsp files to ~/j2ee/jsp 5) URL: http://ise.gmu.edu:8080/offutt/servlet/StudInfoDemo.StudInfoSysDemo ********************************************************************* */ package StudInfoDemo; // Import Servlet Libraries import javax.servlet.*; import javax.servlet.http.*; // Import Java Libraries import java.io.*; import java.util.*; import java.lang.*; // login class // //*********************************************************************** public class loginDemo extends HttpServlet { private static String LoginServlet = "http://apps-inst.ite.gmu.edu:8080/swe432/servlet/StudInfoDemo.loginDemo"; // Hermes private static String JSPLoc = "http://apps-inst.ite.gmu.edu:8080/swe432/jsp/StudInfoDemo/"; public static String classWebSiteURL = "http://www.ise.gmu.edu/~offutt/classes/432/"; public static String FileName = "/apps/tomcat/swe432/WEB-INF/data/Demo-info-F07.xml"; // Form parameters. private static String demoUserID; private static String demoPassWord; // doPost() tells doGet() when the login is invalid. private static boolean invalidID = false; private static String fromJSP; /** ***************************************************** * Overrides HttpServlet's doGet(). * prints the login form. ********************************************************* */ public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { fromJSP = req.getParameter ("jspFrom"); res.setContentType ("TEXT/HTML"); PrintWriter out = res.getWriter (); out.println (""); out.println (""); out.println (""); out.println (" SWE 432-Demo Information Form"); out.println (""); out.println (""); out.println (""); out.println ("
Login form to the student information system
"); if (invalidID) { // called from doPost(), invalid ID entered. invalidID = false; out.println ("
Invalid user ID, password pair. Please try again.

"); } out.println ("
"); // Pass where we came from to doPost() so she can send us back there. if (fromJSP != null) out.println (""); out.println (""); out.println (""); out.println (" "); out.println (" "); out.println (" "); out.println (""); out.println (""); out.println (" "); out.println (" "); out.println (" "); out.println (""); out.println (""); out.println ("
      UserID:
Password:
"); out.println ("
"); // Put the initial focus in the user id box. out.println (" "); out.println (""); out.println (""); out.close (); } /** ***************************************************** * Overrides HttpServlet's doPost(). ********************************************************* */ public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { demoUserID = req.getParameter ("demoUserID"); demoPassWord = req.getParameter ("demoPassWord"); fromJSP = req.getParameter ("jspFrom"); HttpSession session = req.getSession (true); if ((demoUserID.equals ("swe432") && demoPassWord.equals ("swe432")) || (demoUserID.equals ("offutt") && demoPassWord.equals ("offutt")) ) { // successful session.setAttribute ("isLogin", "Yes"); session.setAttribute ("demoUserID", demoUserID); // OKAY ... MAYBE FORWARD TO JSP from "fromJSP" res.sendRedirect (JSPLoc + fromJSP); //res.sendRedirect (JSPLoc + "infoDemo.jsp"); } else { // unsuccessful session.setAttribute ("isLogin", "No"); session.setAttribute ("demoUserID", ""); invalidID = true; doGet (req, res); } } // end of doPost() method } // end of loginDemo class