-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sign.java
64 lines (54 loc) · 2.19 KB
/
Sign.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package Customer;
import jakarta.servlet.RequestDispatcher;
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author HP
*/
public class Sign extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String n = request.getParameter("username");
String p = request.getParameter("password");
PrintWriter out = response.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "");
PreparedStatement ps = con.prepareStatement("select * from customerdetails where username=? and password=?");
ps.setString(1, n);
ps.setString(2,p);
ResultSet rs = ps.executeQuery();
if (rs.next()){
RequestDispatcher rd = request.getRequestDispatcher("Dashboard.jsp");
rd.forward(request, response);
}else{
out.println("<a href='Login.jsp'>Try again</a>");
}
} catch (ClassNotFoundException | SQLException ex) {
out.println(ex.getMessage());
}
}
}