// Login.java // Login.java is the gate for entering the site. It checks if user is a valid // one and redirects the user to the appropriate pages. If user is not a valid one // then we show an error message and post it to the main page package com.project; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class Login extends HttpServlet { static final private String CONTENT_TYPE = "text/html; charset=iso-8859-9"; private Connection connection; private PreparedStatement getInfo; //Initialize global variables public void init() throws ServletException { try { Class.forName("com.mysql.jdbc.Driver"); connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/project"); // prepare the PreparedStatement to get the students info getInfo = connection.prepareStatement("SELECT id,firstname,lastname,password " + "FROM students WHERE id = ?"); } // we throw an UnavailableException to indicate that servlet is // not available catch (Exception ex) { ex.printStackTrace(); throw new UnavailableException(ex.getMessage()); } } //Process the HTTP Post request public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter(); ResultSet result; // get the comming "post" variables String id = request.getParameter("id"); String password = request.getParameter("password"); String dbid = ""; String dbpassword = ""; out.println(""); out.println("