-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertUserServlet.java
47 lines (36 loc) · 1.53 KB
/
InsertUserServlet.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
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class InsertUserServlet extends HttpServlet {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/TIMS";
// Database credentials
static final String USER = "root";
static final String PASS = "Subhi@123";
public void doGet(HttpServletRequest request, HttpServletResponse response){
try{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String role = (String)request.getParameter("role");
String uname = (String)request.getParameter("uid");
String pwd = (String)request.getParameter("pwd");
out.println("==>"+role+uname+pwd+request);
Class.forName(JDBC_DRIVER);
Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
PreparedStatement st = conn.prepareStatement("INSERT INTO users VALUES(?, ?, ?)");
st.setString(1, uname);
st.setString(2, pwd);
st.setString(3, role);
st.executeUpdate();
response.sendRedirect("SessionInitiate?uid="+uname+"&utype="+role+"&new_user=1");
//response.sendRedirect("profile_details.html?uid="+uname+"&utype="+role);
conn.close();
}
catch(Exception e){
System.out.println(e);
}
}
}