Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.servlet.*;
- import javax.servlet.http.*;
- public class Login extends HttpServlet {
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- PrintWriter out = response.getWriter();
- String email = request.getParameter("email");
- String pass = request.getParameter("pass");
- /*
- int rechtenopgehaald = 0;
- try {
- rechtenopgehaald = Validate.CheckRechten(email, pass);
- } catch (InstantiationException ex) {
- Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
- }
- */
- try {
- if(Validate.checkLogin(email, pass))// && rechtenopgehaald==1)
- {
- RequestDispatcher rs = request.getRequestDispatcher("Welcome");
- rs.forward(request, response);
- }else
- {
- out.println("Username or Password incorrect");
- RequestDispatcher rs = request.getRequestDispatcher("index.html");
- rs.include(request, response);
- }
- } catch (InstantiationException ex) {
- Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- import java.sql.*;
- public class Validate {
- public static boolean checkLogin(String email,String pass) throws
- {
- boolean validusercheck = false;
- try{
- //loading drivers for mysql
- Class.forName("com.mysql.jdbc.Driver");
- //creating connection with the database
- Connection hoi=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","user","pass");
- PreparedStatement ps =hoi.prepareStatement("select rechten from Users where email= ? AND pass= ?");
- ps.setString(1, email);
- ps.setString(2, pass);
- ResultSet rs =ps.executeQuery();
- validusercheck=rs.next();
- }catch(ClassNotFoundException | SQLException e)
- {
- System.out.println(e);
- }
- return validusercheck;
- }
- public static int CheckRechten(String email,String pass) throws InstantiationException
- {
- int rechten = 0;
- try{
- //loading drivers for mysql
- Class.forName("com.mysql.jdbc.Driver");
- //creating connection with the database
- Connection hoi=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","user","pass");
- PreparedStatement x =hoi.prepareStatement("select rechten from Users where email= ? AND pass= ?");
- x.setString(1, email);
- x.setString(2, pass);
- ResultSet rs =x.executeQuery();
- while (rs.next()) {
- rechten = rs.getInt(rechten);
- }
- }catch(ClassNotFoundException | SQLException e)
- {
- System.out.println(e);
- }
- return rechten;
- }
- }
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- PrintWriter out = response.getWriter();
- double rente = double.parseouble("rente");
- int jaren = request.getParameter("jaren");
- double lening = request.getParameter("lening");
- double maandrente = berekenmaandrente(rente, lening);
- double aflossing = berekenaflossing(rente, jaren, lening, maandrente);
- out.println("Maandaflossing ="+aflossing);
- out.println("Maandrente ="+maandrente);
- }
- public double getAnnuity(double a, double b, int c) {
- double x = (a/100)/12;
- double y = x/(1-Math.pow(((1+x)),-(c*12))) * b;
- return y;
Add Comment
Please, Sign In to add comment