github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/internal/browser/javaproject/src/main/com/shashi/servlets/UpdateTrainSchedule.java (about) 1 package com.shashi.servlets; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import javax.servlet.RequestDispatcher; 7 import javax.servlet.ServletException; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 13 import com.shashi.beans.TrainBean; 14 import com.shashi.beans.TrainException; 15 import com.shashi.service.TrainService; 16 import com.shashi.service.impl.TrainServiceImpl; 17 18 @SuppressWarnings("serial") 19 @WebServlet("/updatetrainschedule") 20 public class UpdateTrainSchedule extends HttpServlet { 21 22 private TrainService trainService = new TrainServiceImpl(); 23 24 protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 25 res.setContentType("text/html"); 26 PrintWriter pw = res.getWriter(); 27 28 try { 29 30 TrainBean train = new TrainBean(); 31 train.setTr_no(Long.parseLong(req.getParameter("trainno"))); 32 train.setTr_name(req.getParameter("trainname")); 33 train.setFrom_stn(req.getParameter("fromstation")); 34 train.setTo_stn(req.getParameter("tostation")); 35 train.setSeats(Integer.parseInt(req.getParameter("available"))); 36 train.setFare(Double.parseDouble(req.getParameter("fare"))); 37 38 String message = trainService.updateTrain(train); 39 if ("SUCCESS".equalsIgnoreCase(message)) { 40 RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); 41 rd.include(req, res); 42 pw.println("<div class='tab'><p1 class='menu'>Train Updated Successfully!</p1></div>"); 43 } else { 44 RequestDispatcher rd = req.getRequestDispatcher("AdminUpdateTrain.html"); 45 rd.include(req, res); 46 pw.println("<div class='tab'><p1 class='menu'>Error in filling the train Detail</p1></div>"); 47 } 48 } catch (Exception e) { 49 throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 50 } 51 52 } 53 54 }