-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddDoctorServlet.java
More file actions
49 lines (40 loc) · 1.68 KB
/
Copy pathAddDoctorServlet.java
File metadata and controls
49 lines (40 loc) · 1.68 KB
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
package com.servlet;
import com.dao.DoctorDao;
import com.db.DbConnect;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@WebServlet("/AddDoctorServlet")
public class AddDoctorServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String doctorName = request.getParameter("doctorName");
String specialization = request.getParameter("specialization");
String username = request.getParameter("username");
String password = request.getParameter("password");
Connection connection = null;
try {
connection = DbConnect.getConnection();
boolean success = DoctorDao.insertDoctor(connection, doctorName, specialization, username, password);
if (success) {
response.sendRedirect("admin_panel.jsp?addSuccess=1");
} else {
response.sendRedirect("admin_panel.jsp?addError=1");
}
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("admin_panel.jsp?addError=1");
} finally {
PreparedStatement stmt = null;
ResultSet rs = null;
DbConnect.close(connection, null, null);
}
}
}