Professional Documents
Culture Documents
Manan Java 3.3
Manan Java 3.3
Aim: Create an application for online auction using Servlet and JSP.
Objective:
• To understand about JSP Tags.
To learn about how jsp works in Java.
Input/Apparatus Used:
Hardware requirements: Minimum 384MB RAM, 100 GB hard Disk,
processor with 2.1 MHz
Software requirements: Eclipse, NetBeans, IntelliJ, etc.
Procedure/Algorithm/ Pseudocode:
1. AuctionItem Class: This class represents an auction item. It has private fields for
item ID, item name, bidder name, bidder email, bid amount, and whether the bid
should be automatically incremented. It provides getter and setter methods for
accessing and modifying these fields.
2. AuctionServlet Class: This class extends HttpServlet and handles HTTP POST
requests. When a bid is submitted via a form, this servlet creates an AuctionItem
object, populates its fields with the data from the request parameters, sets it as an
attribute of the request, and forwards the request to an index.jsp page for display.
3. AuctionForm.html: This HTML file contains a form for users to enter their bid
details, including item ID, item name, bidder name, email address, bid amount, and
whether they want the bid to be automatically incremented.
4. index.jsp: This JSP (JavaServer Pages) file displays a confirmation message to
the user after their bid has been submitted. It retrieves the auction item details from
the request attribute set by the AuctionServlet and displays them to the user.
5. web.xml: This XML file configures the servlet mapping for the AuctionServlet
class and specifies the welcome file to be served when the web application is
accessed.
Program Code:
1. AuctionServlet.Java:
package com.auction;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
request.setAttribute("auctionItem", item);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
2. AuctionItem.Java:
package com.auction;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AP Auctions - Enter Bid</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #333;
text-align: center;
}
form {
display: flex;
flex-direction: column;
width: 300px;
}
label {
margin-top: 10px;
}
input[type="text"],
input[type="email"],
input[type="number"] {
padding: 8px;
margin-top: 5px;
border-radius: 4px;
border: 1px solid #ddd;
box-sizing: border-box; /* Added to maintain width */
}
input[type="checkbox"] {
margin-top: 15px;
}
button {
background-color: #5cb85c;
color: white;
padding: 10px 15px;
margin-top: 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #4cae4c;
}
</style>
</head>
<body>
<div class="container">
<h2>Welcome to AP Auctions. Please Enter Bid.</h2>
<form action="AuctionServlet" method="post">
<label for="itemID">Item ID:</label>
<input type="text" id="itemID" name="itemID" required>
5. Web.xml:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>AuctionServlet</servlet-name>
<servlet-class>com.auction.AuctionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AuctionServlet</servlet-name>
<url-pattern>/AuctionServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>auctionForm.html</welcome-file>
</welcome-file-list>
</web-app>
web.xml
Output:
Learning Outcomes: