0% found this document useful (0 votes)
20 views5 pages

Onlinebooking

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Onlinebooking

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

index.

jsp

<%--
Document : index
Created on : 11 Nov, 2024, 11:20:34 AM
Author : 251056
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
h1{
text-align: center;
}
form{
width:50%;
background:blueviolet;
color:black;
font-size:200%;
margin: auto;
padding:2px;
}
</style>
</head>
<body>
<h1>WELCOME TO ONLINE BOOKING</h1>
<form action="Bookingform.jsp" method="post">
Name:<input type="text" name="t1" size="20"/><br/>
Online_id:<input type="text" name="t2" size="20"/><br/>
<input type="submit"/>
</form>
</head>
</html>

DBConnection.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author 251056
*
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {


private static final String URL = "jdbc:oracle::thin:@172,16.1.4:1521:saradb";
private static final String USER = "251056"; // Use your database username
private static final String PASSWORD = "welcome"; // Use your database password

public static Connection getConnection() throws SQLException {


try {
Class.forName("oracle.jdbc.driver.OracleDriver");
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (ClassNotFoundException | SQLException e) {
throw new SQLException("Error connecting to the database", e);
}
}
}

Booking.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author 251056
*/
public class Booking {
private String customerName;
private String email;
private String roomType;
private String checkInDate;
private String checkOutDate;

// Getters and setters


public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {


this.customerName = customerName;
}

public String getEmail() {


return email;
}

public void setEmail(String email) {


this.email = email;
}

public String getRoomType() {


return roomType;
}

public void setRoomType(String roomType) {


this.roomType = roomType;
}
public String getCheckInDate() {
return checkInDate;
}

public void setCheckInDate(String checkInDate) {


this.checkInDate = checkInDate;
}

public String getCheckOutDate() {


return checkOutDate;
}

public void setCheckOutDate(String checkOutDate) {


this.checkOutDate = checkOutDate;
}
}

BookingServlet.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
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("/BookingServlet")
public class BookingServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

// Retrieve booking information from the form


String customerName = request.getParameter("customerName");
String email = request.getParameter("email");
String roomType = request.getParameter("roomType");
String checkInDate = request.getParameter("checkInDate");
String checkOutDate = request.getParameter("checkOutDate");

// Create Booking object


Booking booking = new Booking();
booking.setCustomerName(customerName);
booking.setEmail(email);
booking.setRoomType(roomType);
booking.setCheckInDate(checkInDate);
booking.setCheckOutDate(checkOutDate);

// Insert booking into the database


try (Connection connection = DBConnection.getConnection()) {
String sql = "INSERT INTO bookings (customer_name, email, room_type,
check_in, check_out) VALUES (?, ?, ?, ?, ?)";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, customerName);
ps.setString(2, email);
ps.setString(3, roomType);
ps.setString(4, checkInDate);
ps.setString(5, checkOutDate);
ps.executeUpdate();
}
// Redirect to confirmation page
response.sendRedirect("conformationjsp.jsp");
} catch (SQLException e) {
e.printStackTrace();
response.sendRedirect("error.jsp");
}
}
}

Bookingform.jsp

<%--
Document : Bookingform
Created on : 11 Nov, 2024, 11:29:24 AM
Author : 251056
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Online Booking Form</title>
</head>
<body>
<h1>Book a Room</h1>
<form action="BookingServlet" method="post">
<label for="customerName">Name:</label><br>
<input type="text" id="customerName" name="customerName" required><br><br>

<label for="email">Email:</label><br>
<input type="email" id="email" name="email" required><br><br>

<label for="roomType">Room Type:</label><br>


<select id="roomType" name="roomType">
<option value="Single">Single</option>
<option value="Double">Double</option>
<option value="Suite">Suite</option>
</select><br><br>

<label for="checkInDate">Check-in Date:</label><br>


<input type="date" id="checkInDate" name="checkInDate" required><br><br>

<label for="checkOutDate">Check-out Date:</label><br>


<input type="date" id="checkOutDate" name="checkOutDate" required><br><br>

<input type="submit">
</form>
</body>
</html>

conformationjsp.jsp
<%--
Document : conformationjsp
Created on : 11 Nov, 2024, 11:30:21 AM
Author : 251056
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Booking Confirmation</title>
</head>
<body>
<h1>Booking Successful!</h1>
<p>Your room has been booked. We will send a confirmation email shortly.</p>
</body>
</html>

You might also like