Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.sql.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class LoginAuth extends HttpServlet {
- private ServletConfig config;
- public void init(ServletConfig config)
- throws ServletException {
- this.config = config;
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- HttpSession session = request.getSession(true);
- PrintWriter out = response.getWriter();
- String connectionURL = "jdbc:mysql://mysql.cmi-hro.nl:3306/cmi0814619";
- Connection connection = null;
- ResultSet rs;
- String databaseUsername;
- String databasePassword;
- String username = request.getParameter("user");
- String password = request.getParameter("pass");
- response.setContentType("text/html");
- try {
- // Load the database driver
- Class.forName("com.mysql.jdbc.Driver");
- // Get a Connection to the database
- connection = DriverManager.getConnection(connectionURL, "cmi0814619", "0000000");
- //Add the data into the database
- String sql = "select achternaam,reserverings_nr from cmi0814619.klanten";
- Statement s = connection.createStatement();
- s.executeQuery(sql);
- rs = s.getResultSet();
- while (rs.next()) {
- databaseUsername = rs.getString("achternaam");
- databasePassword = rs.getString("reserverings_nr");
- if (databaseUsername.equals(username) && databasePassword.equals(password)){
- session.setAttribute("userName", username);
- session.setAttribute("passwrd", password);
- String nextJSP = "enq_p1.jsp";
- response.sendRedirect(nextJSP);
- }
- rs.close();
- s.close();
- }
- } catch (Exception e) {
- System.out.println("Exception is ;" + e);
- }
- String nextJSP = "fout_ingelogd.jsp";
- response.sendRedirect(nextJSP);
- }
- }
Add Comment
Please, Sign In to add comment