0% found this document useful (0 votes)
2 views10 pages

JAVA_3_2

The document outlines an experiment for creating a web application using Servlets and JSP to print messages in a web browser. It includes the aim, software requirements, algorithm, and code for the index.jsp and functions.java files. Additionally, it discusses learning outcomes related to servlets, JSP, and Tomcat server integration.

Uploaded by

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

JAVA_3_2

The document outlines an experiment for creating a web application using Servlets and JSP to print messages in a web browser. It includes the aim, software requirements, algorithm, and code for the index.jsp and functions.java files. Additionally, it discusses learning outcomes related to servlets, JSP, and Tomcat server integration.

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE &


ENGINEERING

Experiment 3.2

Student Name: Ankit Kumar UID: 20BCS7935


Branch: BE-CSE Section/Group: 20BCS707 A
Semester: 5TH
Subject Name : PBLJ Lab Subject Code: 20CSP-321

1.Aim: Create a Servlet/ application with a facility to print any message


on web browser.
.

2.Software/Hardware Requirements: VS Code or Eclipse

3. Algorithm/ PsuedoCode:

STEP 1- Create a index.jsp file in a webapp directory.


STEP 2 - Create a package named as fun and create a java file named as
functions.java .
STEP 3 - functions.java file contains the logic for checking the validation in
the form of submitting.
STEP 4- At Last start the server and display the output on the web browser.
STEP 5- EXIT
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

CODE:

Index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<style>
h1{
margin: auto;
width: 60%;
padding-left: 100px;
}
body {
background:orange;
color: white;
}
.fall {
background: grey;
color: white;
border: 2px solid blue;
width: 45%;
margin:auto;
}
.input-group{
position: relative;
margin: 23px;
left: 175px;
}
button{
position: relative;
left: 35%
}
button:hover{
cursor:pointer;
background: black;
color: white;
}
h3{
margin: auto;
width: 40%;
padding: 5px;
}

</style>
</head>
<body>
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

<h1>Welcome the AP Auctions, Please Enter the Bid</h1>


<form class="fall" name="register_form" action="<
%=request.getContextPath()%>/functions" method="post" >
<div class="input-group mb-2">
<input type="text"name="name" id="name"
onkeypress="return /[0-9a-zA-Z]/i.test(event.key)" class="form-control
input_user" required="required"
placeholder="Item
ID">
</div>
<p class="error" id="name_id"></p>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas
fa-user"></i></span>
</div>
<input type="text" name="branch" id="branch"
onkeypress="return /[0-9a-zA-Z]/i.test(event.key)" class="form-control
input_user" required="required"
placeholder="Item
Name">
</div>
<p class="error" id="branch_id"></p>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i class="fas
fa-user"></i></span>
</div>
<input type="text" name="course" id="course"
onkeypress="return /[0-9a-zA-Z]/i.test(event.key)" class="form-control
input_user" required="required"
placeholder="Your
Name">
</div>
<p class="error" id="course_id"></p>
<div class="input-group mb-2">
<div class="input-group-append">
<span class="input-group-text"><i
class="fas fa-user"></i></span>
</div>
<input type="email" name="email"
id="email"onkeypress="return /[0-9a-zA-Z.@_]/i.test(event.key)" class="form-
control input_user" required="required"

placeholder="Email">
</div>
<p class="error" id="email_id"></p>

<div class="input-group mb-2">


<div class="input-group-append">
<span class="input-group-text"><i
class="fas fa-user"></i></span>
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

</div>
<input type="number" id="number"
onKeyPress="if(this.value.length==10) return false;" name="number"
class="form-control input_user" required="required"

placeholder="Amount Bid">
</div>
<p class="error"
id="number_id"></p>
<button type="submit" onclick=hide()>Submit Bid</button>
</form>
<script>
document.getElementById("name").addEventListener("keypress", myname);
document.getElementById("name").addEventListener("mouseover",
myname);
function myname() {
var name= document.register_form.name.value;
var paragraph = document.getElementById("name_id");
if(name.length==0){
paragraph.textContent="Please enter your Id !!";
document.register_form.name.focus();
}
if(name.length>5 && name.length!=0){
paragraph.textContent="\ID should not be greater than
5 character !!!";
document.register_form.name.focus();
}
if(name.length<5){
paragraph.textContent="";
}
}

document.getElementById("email").addEventListener("keypress",
myemail);
document.getElementById("email").addEventListener("mouseover",
myemail);
function myemail() {
var email= document.register_form.email.value;
var paragraph = document.getElementById("email_id");
if(email.length==0){
paragraph.textContent="Please enter your email !!";
document.register_form.email.focus();
}
else if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+
$/.test(email))){
paragraph.textContent="Enter valid email !!!";
document.register_form.email.focus();
}
else{
paragraph.textContent="";
}
}
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

document.getElementById("branch").addEventListener("keypress",
mybranch);
document.getElementById("branch").addEventListener("mouseover",
mybranch);
function mybranch() {
var branch= document.register_form.branch.value;
var paragraph = document.getElementById("branch_id");
if(branch.length<1){
paragraph.textContent="Please enter your Item
Name !!";
document.register_form.branch.focus();
}
else{
paragraph.textContent="";
}
}

document.getElementById("course").addEventListener("keypress",
mycourse);
document.getElementById("course").addEventListener("mouseover",
mycourse);
function mycourse() {
var course= document.register_form.course.value;
var paragraph = document.getElementById("course_id");
if(course.length<1){
paragraph.textContent="Please enter your Name !!";
document.register_form.course.focus();
}
else{
paragraph.textContent="";
}
}
document.getElementById("number").addEventListener("keypress",
mynumber);
document.getElementById("number").addEventListener("mouseover",
mynumber);
function mynumber() {
var number= document.register_form.number.value;
var paragraph = document.getElementById("number_id");
if(number.length==0){
paragraph.textContent="Please enter your Amount
Bid !!";
document.register_form.email.focus();
}
else if(!(/^[6-9]\d{9}$/.test(number))){
paragraph.textContent="Enter valid Amount Bid !!!";
document.register_form.number.focus();
}
else{
paragraph.textContent="";
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

}
}

</script>
<h3>Bid Submitted</h3>
<h3>Your bid is now active. if your bid is successful, you will be
notified within 24HRS</h3>
<h3> Item id: <%=request.getAttribute("ans") %></h3> <br>
<h3> Item Name: <%=request.getAttribute("ans1") %></h3> <br/>
<h3> Your Name <%=request.getAttribute("ans2") %></h3><br/>
<h3> Email:<%=request.getAttribute("ans3") %></h3><br/>
<h3> Your Amount: <%=request.getAttribute("ans4") %></h3><br/>
</body>
</html>
Functions.java

package fun;

import java.util.*;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

/**

* Servlet implementation class functions

*/
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

@WebServlet(name="functions",urlPatterns={"/
functions"})

public class functions extends HttpServlet {

protected void doPost(HttpServletRequest request,


HttpServletResponse response) throws ServletException,
IOException {

String a=request.getParameter("name");

String b=request.getParameter("branch");

String c=request.getParameter("course");

String d=request.getParameter("email");

String e=request.getParameter("number");

try {

String ans=a;

String ans1=b;

String ans2=c;

String ans3=d;

String ans4=e;

request.setAttribute("ans",ans);

request.setAttribute("ans1",ans1);

request.setAttribute("ans2",ans2);

request.setAttribute("ans3",ans3);
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

request.setAttribute("ans4",ans4);

request.getRequestDispatcher("index.jsp").forward(reque
st,response);

}catch(Exception e1) {

System.out.println(e1);

OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING

Learning outcomes (What I have learnt):

1. Learn About the servlet


2. Learn about jsp and dynamic web project
3. Learn about the tomcat server and its integrations with the
java.

You might also like