CREATE TABLE students (
student_id INT PRIMARY KEY,
name VARCHAR(255),
department VARCHAR(255)
);
CREATE TABLE teachers (
teacher_id INT PRIMARY KEY,
name VARCHAR(255),
department VARCHAR(255)
);
CREATE TABLE departure_requests (
request_id INT PRIMARY KEY AUTO_INCREMENT,
student_id INT,
reason TEXT,
status ENUM('pending', 'approved', 'rejected'),
FOREIGN KEY (student_id) REFERENCES students(student_id)
);
]]>
@WebServlet("/submitRequest")
public class SubmitRequestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int studentId = Integer.parseInt(request.getParameter("student_id"));
String reason = request.getParameter("reason");
DepartureRequest request = new DepartureRequest(studentId, reason);
DepartureService service = new DepartureService();
boolean result = service.submitRequest(request);
if(result) {
sendEmail("admin@example.com", "New Departure Request", "A new departure request has been submitted.");
response.sendRedirect("success.html");
} else {
response.sendRedirect("error.html");
}
}
private void sendEmail(String to, String subject, String body) {
// Email sending logic here
}
}
]]>