OneCompiler

sru

106

package com.hospital.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/EditPatientServlet")
public class EditPatientServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Fetch parameters from the form
    String email = request.getParameter("email");
    String phone = request.getParameter("phone");
    String notes = request.getParameter("notes");
    
    // Validate inputs (basic validation for demonstration)
    if (email == null || email.isEmpty() || phone == null || phone.isEmpty() || notes == null || notes.isEmpty()) {
        request.setAttribute("message", "Error: All fields are required.");
        request.getRequestDispatcher("/editPatient.jsp").forward(request, response);
        return;
    }
    
    // Simulate update operation (replace with your actual database logic)
    boolean updateSuccessful = true; // Assume update is successful for demonstration
    
    if (updateSuccessful) {
        request.setAttribute("message", "Patient information updated successfully.");
    } else {
        request.setAttribute("message", "Error: Failed to update patient information.");
    }
    
    // Forward back to editPatient.jsp with appropriate message
    request.getRequestDispatcher("/editPatient.jsp").forward(request, response);
}

}