github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/internal/browser/javaproject/src/main/com/shashi/servlets/UserAvailServlet.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.constant.UserRole; 16 import com.shashi.service.TrainService; 17 import com.shashi.service.impl.TrainServiceImpl; 18 import com.shashi.utility.TrainUtil; 19 20 @SuppressWarnings("serial") 21 @WebServlet("/useravail") 22 public class UserAvailServlet extends HttpServlet { 23 private TrainService trainService = new TrainServiceImpl(); 24 25 protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { 26 res.setContentType("text/html"); 27 PrintWriter pw = res.getWriter(); 28 29 TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER); 30 31 try { 32 33 String trainNo = req.getParameter("trainno"); 34 TrainBean train = trainService.getTrainById(trainNo); 35 if (train != null) { 36 RequestDispatcher rd = req.getRequestDispatcher("UserHome.html"); 37 rd.include(req, res); 38 pw.println( 39 "<div class='tab'>" + " <p1 class='menu'>" + " Hello " + TrainUtil.getCurrentUserName(req) 40 + " ! Welcome to our new NITRTC Website" + " </p1>" + " </div>"); 41 pw.println("<div class='main'><p1 class='menu'>Available Seats are <p2 class=\"red\"> " 42 + train.getSeats() + " Seats</p2></p1></div>"); 43 pw.println("<div class='tab'>" + "<table>" + "<tr><td class='blue'>Train Name :</td><td>" 44 + train.getTr_name() + "</td></tr>" + "<tr><td class='blue'>Train Number :</td><td>" 45 + train.getTr_no() + "</td></tr>" + "<tr><td class='blue'>From Station :</td><td>" 46 + train.getFrom_stn() + "</td></tr>" + "<tr><td class='blue'>To Station :</td><td>" 47 + train.getTo_stn() + "</td></tr>" + "<tr><td class='blue'>Available Seats:</td><td>" 48 + train.getSeats() + "</td></tr>" + "<tr><td class='blue'>Fare (INR) :</td><td>" 49 + train.getFare() + " RS</td></tr>" + "</table>" + "</div>"); 50 } else { 51 RequestDispatcher rd = req.getRequestDispatcher("Availability.html"); 52 rd.include(req, res); 53 54 pw.println("<div class='tab'><p1 class='menu'>Train No." + trainNo + " is Not Available !</p1></div>"); 55 } 56 } catch (Exception e) { 57 throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage()); 58 } 59 60 } 61 62 }