• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Online Reservation/Ticket Booking System

 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is The first page which has only one Submit button which when clicked leads to display.java servlet


display.java thisfile shows the status of seats available in a bus


the hyperlink leads to the seat.java file


this will allow user to fill up the details form and book a ticket and will lead to booked.java


What I Want to show is that after a ticket is booked it should reduce that no from the array list which was chosen at the time of booking wherein it shows a blank array list!

 
sonu raj
Ranch Hand
Posts: 43
Android C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was a mistake you just created a new LinkedList in Booked.java but you didn't initialized it. One more thing you were passing a String to remove() method which is not correct. you should first convet it to Integeras I did . I have used session to initialize it and it is working.
The Edited portion is highlighted

Display.java

import java.io.IOException;
import java.io.PrintWriter;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.util.*;
import javax.sql.*;
import java.sql.*;
import java.lang.*;

public class Display extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
try {
out.println("<html>");
out.println("<body>");
LinkedList l = new LinkedList();
l.add("1");
l.add("2");
l.add("3");
l.add("4");
l.add("5");
l.add("6");
l.add("7");
l.add("8");
l.add("9");
l.add("10");
HttpSession session = request.getSession(true);
session.setAttribute("linked", l);


out.println("<center><h1>" + l + "</h1>");
out.println("<a href = 'Seat'>Book A Ticket</a>");
} catch (Exception e) {
out.println(e);
}
}
}






Book.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.sql.*;
import javax.sql.*;
import java.util.*;

/**
*
* @author Pranit
*/
public class Booked extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String cust_name = request.getParameter("cust_name");
String dest1 = request.getParameter("dest1");
String dest2 = request.getParameter("dest2");
String seat = request.getParameter("seat");
int n=0;
HttpSession session = request.getSession(true);
try{n=Integer.parseInt(seat);}catch(Exception e){}
LinkedList l =(LinkedList) session.getAttribute("linked");

try{
Class.forName("com.mysql.jdbc.Driver");
Connection cn = DriverManager.getConnection("jdbc:mysql:///bus","root","admin");
PreparedStatement s = cn.prepareStatement("insert into travel values(?,?,?,?)");
s.setString(1, cust_name);
s.setString(2, dest1);
s.setString(3,dest2);
s.setString(4,seat);
s.executeUpdate();
out.println("Ticket has been booked");
try{
l.remove(n-1);}catch(Exception e){out.print(e);}

out.println("<h1>"+l+"</h1>");
}catch(Exception e){
out.println(e);
}
}
}

Rest of your code is correct. All the best





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic