Guest User

Untitled

a guest
Jun 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.logging.Level;
  3. import java.util.logging.Logger;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6.  
  7. public class Login extends HttpServlet {
  8.  
  9. public void doPost(HttpServletRequest request, HttpServletResponse response)
  10. throws ServletException, IOException {
  11. response.setContentType("text/html;charset=UTF-8");
  12. PrintWriter out = response.getWriter();
  13.  
  14. String email = request.getParameter("email");
  15. String pass = request.getParameter("pass");
  16.  
  17. /*
  18. int rechtenopgehaald = 0;
  19. try {
  20. rechtenopgehaald = Validate.CheckRechten(email, pass);
  21. } catch (InstantiationException ex) {
  22. Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
  23. }
  24. */
  25. try {
  26. if(Validate.checkLogin(email, pass))// && rechtenopgehaald==1)
  27. {
  28. RequestDispatcher rs = request.getRequestDispatcher("Welcome");
  29. rs.forward(request, response);
  30. }else
  31. {
  32. out.println("Username or Password incorrect");
  33. RequestDispatcher rs = request.getRequestDispatcher("index.html");
  34. rs.include(request, response);
  35. }
  36. } catch (InstantiationException ex) {
  37. Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
  38. }
  39. }
  40. }
  41.  
  42. import java.sql.*;
  43.  
  44. public class Validate {
  45. public static boolean checkLogin(String email,String pass) throws
  46. {
  47. boolean validusercheck = false;
  48. try{
  49. //loading drivers for mysql
  50. Class.forName("com.mysql.jdbc.Driver");
  51.  
  52. //creating connection with the database
  53. Connection hoi=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","user","pass");
  54. PreparedStatement ps =hoi.prepareStatement("select rechten from Users where email= ? AND pass= ?");
  55. ps.setString(1, email);
  56. ps.setString(2, pass);
  57. ResultSet rs =ps.executeQuery();
  58. validusercheck=rs.next();
  59.  
  60. }catch(ClassNotFoundException | SQLException e)
  61. {
  62. System.out.println(e);
  63. }
  64. return validusercheck;
  65.  
  66. }
  67.  
  68. public static int CheckRechten(String email,String pass) throws InstantiationException
  69. {
  70. int rechten = 0;
  71.  
  72. try{
  73.  
  74. //loading drivers for mysql
  75. Class.forName("com.mysql.jdbc.Driver");
  76.  
  77. //creating connection with the database
  78. Connection hoi=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","user","pass");
  79. PreparedStatement x =hoi.prepareStatement("select rechten from Users where email= ? AND pass= ?");
  80. x.setString(1, email);
  81. x.setString(2, pass);
  82. ResultSet rs =x.executeQuery();
  83.  
  84. while (rs.next()) {
  85. rechten = rs.getInt(rechten);
  86. }
  87.  
  88. }catch(ClassNotFoundException | SQLException e)
  89. {
  90. System.out.println(e);
  91. }
  92. return rechten;
  93.  
  94. }
  95.  
  96. }
  97.  
  98. public void doGet(HttpServletRequest request, HttpServletResponse response)
  99. throws ServletException, IOException {
  100. response.setContentType("text/html;charset=UTF-8");
  101. PrintWriter out = response.getWriter();
  102.  
  103. double rente = double.parseouble("rente");
  104. int jaren = request.getParameter("jaren");
  105. double lening = request.getParameter("lening");
  106.  
  107. double maandrente = berekenmaandrente(rente, lening);
  108. double aflossing = berekenaflossing(rente, jaren, lening, maandrente);
  109. out.println("Maandaflossing ="+aflossing);
  110. out.println("Maandrente ="+maandrente);
  111. }
  112.  
  113. public double getAnnuity(double a, double b, int c) {
  114. double x = (a/100)/12;
  115. double y = x/(1-Math.pow(((1+x)),-(c*12))) * b;
  116. return y;
Add Comment
Please, Sign In to add comment