Guest User

Untitled

a guest
May 31st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. package JSPMultipleForms;
  2.  
  3. import java.io.*;
  4. import java.sql.*;
  5. import javax.servlet.*;
  6. import javax.servlet.http.*;
  7.  
  8. public class LoginAuthentication2 extends HttpServlet{
  9.  
  10. private ServletConfig config;
  11.  
  12. public void init(ServletConfig config)
  13. throws ServletException{
  14. this.config=config;
  15. }
  16. public void doPost(HttpServletRequest request, HttpServletResponse response)
  17. throws ServletException,IOException{
  18.  
  19. PrintWriter out = response.getWriter();
  20.  
  21. String connectionURL = "jdbc:mysql://mysql.cmi-hro.nl:3306/cmi0814147";
  22. Connection connection=null;
  23. ResultSet rs;
  24. String userName=new String("");
  25. String passwrd=new String("");
  26. response.setContentType("text/html");
  27. try {
  28. // Load the database driver
  29. Class.forName("com.mysql.jdbc.Driver");
  30. // Get a Connection to the database
  31. connection = DriverManager.getConnection(connectionURL, "cmi0814147", "..........");
  32. //Add the data into the database
  33. String sql = "select user,password from cmi0814147.user";
  34. Statement s = connection.createStatement();
  35. s.executeQuery (sql);
  36. rs = s.getResultSet();
  37. while (rs.next ()){
  38. userName=rs.getString("user");
  39. passwrd=rs.getString("password");
  40. }
  41. rs.close ();
  42. s.close ();
  43. }catch(Exception e){
  44. System.out.println("Exception is ;"+e);
  45. }
  46. if(userName.equals(request.getParameter("user"))
  47. && passwrd.equals(request.getParameter("pass"))){
  48.  
  49. String nextJSP = "beheer.jsp";
  50. response.sendRedirect(nextJSP);
  51.  
  52. }
  53. else{
  54. String nextHTML = "index.html";
  55. response.sendRedirect(nextHTML);
  56.  
  57. }
  58. }
  59. }
Add Comment
Please, Sign In to add comment