Java Servlet Registration and Validation
Java Servlet Registration and Validation
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="Registration" method="post">
User name: <input type="text" name="uname"> <br><br>
Password: <input type="password" name="pw"><br><br>
Email Id: <input type="text" name="email"> <br><br>
Country: <select name="coun">
<option>select...
<option> India
<option> Bangladesh
<option> Bhutan
<option> Canada
</select> <br><br>
<input type="submit" value=" Registration">
</form>
</body>
</html>
[Link]
/*
* 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 [Link].*;
import [Link];
import [Link].*;
import
[Link].*;
import [Link].*;
/**
*
* @author spdc
*/
public class Registration extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
[Link](2,pass);
[Link](3,email);
[Link](4,country);
[Link]();
/* TODO output your page here. You may use following sample code. */ [Link]("<!
DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>Servlet
Registration</title>"); [Link]("</head>");
[Link]("<body>");
[Link]("<h1>" + " Data Insert Successfully</h1>");
}
catch(Exception e)
{[Link](e);}
[Link]("</body>");
[Link]("</html>");
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo()
{ return "Short description";
}// </editor-fold>
Output :-
Practical No.2
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<body>
<form method="post" action="Validate">
UserName:<input type="text" name="un"><br><br>
Password:<input type="password" name="pw"><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
[Link]
/*
* 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 [Link].*;
import [Link].*;
import
[Link].*;
/**
*
* @author spdc
*/
public class Validate extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
[Link]("text/html");
PrintWriter out=[Link]();
String
Username=[Link]("un");
String
Password=[Link]("pw");
if([Link]("Servlet"))
{
[Link]("s1username",Username);
[Link]("s1password",Password);
RequestDispatcher rd=[Link]("/Welcome");
[Link](request,response);
}
else
{
[Link]("Incorrect password");
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
RequestDispatcher
rd=[Link]("/[Link]");
[Link](request,response);
}
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
[Link]
/*
* 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 spdc
*/
public class Welcome extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Output :-
B. Create a servlet that uses Cookies to store the number of times a user
has visited a servlet.
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="Servlet1" method="GET">
Click for Visit <input type="Submit" value="Go">
</form>
</body>
</html>
Servlet1
/*
* 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 [Link].*;
import
[Link].*;
import [Link].*;
/**
*
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
* @author spdc
*/
public class Servlet1 extends HttpServlet
{
private int i=1;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException,ServletException
{
[Link]("text/html");
PrintWriter out = [Link]();
String k=[Link](i); Cookie
c=new Cookie("visit",k);
[Link](c);
int j=[Link]([Link]());
if(j==1)
{
[Link]("This is the first time you are visiting this page");
}
else
{
synchronized([Link])
{
[Link]("You visited this page"+i+"times");
}
}
i++;
}
}
Output :-
Source Code :
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="ColorServlet" method="post">
<label>Select Background Color</label>
<input type="color" name="bgColor" value="#ffffff">
<input type="submit" value="Apply Color">
</form>
</body>
</html>
[Link]>
/*
* 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 [Link].*;
import
[Link].*;
import [Link].*;
/**
*
* @author spdc
*/
public class ColorServlet extends HttpServlet {
DisplayServlet>
/*
* 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 [Link].*;
import
[Link].*;
import [Link].*;
/**
*
* @author spdc
*/
public class DisplayServlet extends HttpServlet {
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String bgColor="#ffffff";
Cookie[]
cookies=[Link]();
if(cookies !=null){
for(Cookie cookie: cookies){
if("bgColor".equals([Link]())){
bgColor=[Link]();
break;
}
}
}
[Link]("text/html");
PrintWriter out = [Link]();
/* TODO output your page here. You may use following sample code. */
[Link]("<!DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>Colored
Page</title>"); [Link]("</head>");
[Link]("<body style='background-color: "+bgColor+ ";' >");
[Link]("<h1>Welcome!</h1>");
[Link]("<p>Your preferred background color has been applied.</p>");
[Link]("<a href='[Link]'>Change Color</a>");
[Link]("</body>");
[Link]("</html>");
}
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
Output :-
Practical No.3
Uploading file :-
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="FileUploadServlet"
method="post" enctype="multipart/form-data">
Select File to Upload:<input type="file" name="file" id="file">
Destination<input type="text" value="/tmp" name="destination">
<br>
<input type="submit" value="Upload file" name="upload" id="upload">
</form>
</body>
</html>
[Link]
package
fileservletapp; import
[Link].*; import
[Link].*;
import [Link].*;
import
[Link];
import [Link];
@MultipartConfig
/**
*
* @author SPDC
*/
public class FileUploadServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
String
sfilePart=[Link]("file").toString();
[Link]("<br>filePart:"+sfilePart);
String
filename=[Link]().toString();
[Link]("br><br><hr>file name:"+filename);
OutputStream os=null;
InputStream
is=null; try {
os= new FileOutputStream(new File(path + [Link] + filename));
is= [Link]();
int read = 0;
byte[] b= new byte[1024];
while ((read = [Link](b)) != -1)
{
[Link](b,0, read);
}
[Link]("<br>file uploaded sucessfully...!!");
}
catch(FileNotFoundException e){[Link](e);}
}}
Output :-
Downloading a file :-
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>File Download Application</h1>
Click <a href="FileDownloadServlet?filename=[Link]">Sample Chapter</a>
<br/><br/>
</body>
[Link]
package
filedownloadapp; import
[Link].*;
import [Link].*;
import
[Link].*;
public class FileDownloadServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
{ [Link]("APPLICATION/OCTET-STREAM");
String filename = [Link]("filename");
ServletContext context = getServletContext();
InputStream is = [Link]("/" + filename);
ServletOutputStream os = [Link]();
[Link]("Content-Disposition","attachment; filename=\"" + filename +
"\"");
// if comment this statement then it will ask you about the editor with which you want
to open the file
int i;
byte b[]=new byte[1024];
while ((i=[Link](b)) != -1) {
[Link](b);
}
[Link]();
[Link]();
}
}
Output :-
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Online Exam</title>
</head>
<body>
<center>Online Exam</center>
<form action="Marks" method="post">
<hr>
<div>
1. What is RDBMS?<br>
<input type="radio" name="q1" value="1" required> Relational Database
System<br>
<input type="radio" name="q1" value="2"> Relational<br>
<input type="radio" name="q1" value="3"> Database<br>
<input type="radio" name="q1" value="4"> Redbms<br>
<input type="hidden" name="ans1" value="1">
</div>
<hr>
<div>
2. What is computer?<br>
<input type="radio" name="q2" value="1" required> Brain<br>
<input type="radio" name="q2" value="2"> Electronic device<br>
<input type="radio" name="q2" value="3"> Calculator<br>
<input type="radio" name="q2" value="4"> Mobile<br>
<input type="hidden" name="ans2" value="2">
</div>
<hr>
<div>
3. Who is joker?<br>
<input type="radio" name="q3" value="1" required> Clown<br>
<input type="radio" name="q3" value="2"> Man<br>
<input type="radio" name="q3" value="3"> Dog<br>
<input type="radio" name="q3" value="4"> Funny man<br>
<input type="hidden" name="ans3" value="1">
</div>
<hr>
<input type="hidden" name="total" value="3">
<input type="submit" value="Submit">
</form>
</body>
</html>
[Link]
package dbapp;
import
[Link].*;
import
[Link].*;
import [Link].*;
import [Link].*;
try {
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
[Link]("<html><head><title>Online
Exam</title></head><body>"); [Link]("<form method='post'
action='Marks'>");
[Link]("<center><h2>Online Exam</h2></center>");
// Connect to DB
Connection con =
[Link]("jdbc:mysql://localhost:3306/mysql", "root",
"12345"); Statement st = [Link]();
int i = 0;
while ([Link]()) {
i++;
[Link]("<hr>");
[Link]("<b>Q" + [Link](1) + ": " + [Link](2) + "</b><br>");
[Link]("<input type='radio' name='" + i + "' value='1'> " +
[Link](3) + "<br>");
[Link]("<input type='radio' name='" + i + "' value='2'> " +
[Link](4) + "<br>");
[Link]("<input type='radio' name='" + i + "' value='3'> " +
[Link](5) + "<br>");
[Link]("<input type='radio' name='" + i + "' value='4'> " +
[Link](6) + "<br>");
[Link]("</form></body></html>");
// Close resources
[Link]();
[Link]();
[Link]();
} catch (Exception e) {
[Link]("<p style='color:red;'>ERROR: " + [Link]() + "</p>");
}
}
}
[Link]
package dbapp;
import
[Link].*;
import
[Link].*;
import [Link].*;
try {
[Link]("<html><head><title>Result</title></head><body>");
[Link]("<center><h2>Result</h2></center>");
Output :-
OR
Source Code :-
[Link]
<html>
<body>
</body>
</html>
[Link]
package nonblkapp;
import [Link].*;
import [Link];
import
[Link];
import [Link].*;
AsyncContext ac = null;
{ input = in;
ac = c;
@Override
{ [Link]();
{ [Link]();
[Link]();
[Link]
package nonblkapp;
import [Link].*;
import
[Link].*;
import [Link];
import [Link].*;
{"/ReadingNonBlockingServlet"},asyncSupported = true )
@Override
{ [Link]("text/html");
AsyncContext ac = [Link]();
ServletInputStream
in=[Link]();
[Link](new ReadingListener(in,ac));
[Link]:
package
nonblkapp; import
[Link].*;
import
[Link];
import [Link];
import [Link];
import
[Link];
import [Link].*;
import [Link];
import [Link].*;
@Override
ServletException, IOException {
[Link]("text/html");
ServletContext c = getServletContext();
InputStream is = [Link]("/"+filename);
[Link]() + "/ReadingNonBlockingServlet";
[Link]("<h1>File Reader</h1>");
//[Link]();
[Link]();
String text =
"";
[Link]("Reading started...");
[Link](text);
[Link]();
[Link](text+"<br>");
[Link]();
try
[Link](1000);
[Link](ex);
[Link]("Reading completed...");
[Link]();
[Link]();
Output :-
Practical No.4
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="[Link]">
Enter your name:<input type="text" name="myname"<br>
Enter your mail:<input type="text" name="mymailid"<br>
<input type="submit" value="submit">
</form>
</body>
</html>
[Link]
<%--
Document : ImplicitObjectEx
Created on : 4 Sep, 2025, 10:21:35
AM Author : spdc
--%>
<%@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>
</head>
<body>
<h1>Use of Intrinsic Objects in JSP</h1>
<h1>Request Object</h1>
Query String<%=[Link]()%><br>
Context Path<%=[Link]()%><br>
Remote Host<%=[Link]()
%><br>
<h1>Response Object</h1>
Character Encoding Type<%=[Link]()
%><br> Content Type<%=[Link]()%><br> Locale<
%=[Link]()%><br>
Output :-
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Shopping Cart</div>
<form action="[Link]" method="post">
<table>
<tr>
<td>
Select Product!
</td>
<td><select name="Pname">
<option value="T-shirt"> T-shirt</option>
<option value="shirt"> shirt</option>
<option value="Jeans"> Jeans</option>
<option value="Trouser"> Trouser</option>
</select>
</td>
</tr>
<tr>
<td>Enter the product quantity:</td>
<td><input type="text" name="t1" value=""/></td>
</tr>
<tr><td>
<input type="submit" value="Click" />
</td></tr>
</table>
</form>
</body>
</html>
[Link]
<%--
Document : Brand
Created on : Sep 4, 2025, 10:52:59
AM Author : SPDC1
--%>
%>
<form action="[Link]">
<table>
<tr>
<td><select name="brd">
<option value="LEE Copper">LEE Copper</option>
<option value="Zara">Zara</option>
<option value="Nike">Nike</option>
<option value="Ajio">Ajio</option>
<option value="H&M">H&M</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="Checkout"/>
</td>
</tr>
</table>
</form>
</body>
</html>
[Link]
<%--
Document : Checkout
Created on : 4 Sep, 2025, 12:32:39
PM Author : spdc
--%>
</head>
<body>
<%
[Link]("Product Name: "+[Link]("Pname")+"</br>");
[Link]("Product Quantity: "+[Link]("qut")+"</br>");
[Link]("Brand Name: "+[Link]("brd")+"</br>");
%>
</body>
</html>
Output :-
Practical No.5
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>New User Registration Page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form Action="[Link]">
<h1> New User Registration Page</h1>
Enter User Name<input type="text" name="txtName"><br>
Enter Password<input type="password" name="txtPass1"><br>
Re-Enter Password<input type="password" name="txtPass2"><br>
Enter Email<input type="text" name="txtEmail"><br>
Enter Country Name<select name="txtCon">
<option>India</option>
<option>France</option>
<option>England</option>
<option>Argentina</option>
</select><br>
<input type="submit" value="REGISTER"><input type="reset">
</form>
</body>
</html>
[Link]
<%--
Document : REGISTRATION
Created on : 11 Sep, 2025, 10:47:22
AM Author : spdc
--%>
[Link]
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
Output :-
B. Create an html page with fields, eno, name, age, desg, salary. Now on
submit this data to a JSP page which will update the employee table of database
with matching eno.
Source Code :-
[Link]
<html>
<body>
<form action="[Link]" >
Enter Employee Number<input type="text"
name="txtEno" ><br> Enter Salary to update<input
type="text" name="txtSal" ><br>
</form>
</body>
</html>
[Link]
<%@page contentType="text/html" import="[Link].*" %>
<html>
<body>
<h1>Updating Employee Record</h1>
<%
String
eno=[Link]("txt
Eno"); String sal =
[Link]("txtSal")
; try{
[Link]("[Link]
[Link]"); Connection con =
[Link]("jdbc:mysql://localhost:3306/emp
db","root","tiger"); PreparedStatement stmt =
[Link]("select * from emp where empno=?");
[Link](1, eno);
ResultSet rs =
[Link]();
if([Link]()){
[Link]
g(1, sal);
[Link]
g(2, eno);
[Link]
Update();
}
else{
[Link]("<h1>Employee Record not exist !!!!!</h1>");
}catch(Exception e){[Link](e);}
%>
</body>
</html>
Output :-
Practical No.6
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>Currency Converter</title></head>
<body>
<form action="beanServlet">
Enter Amount<input type="text" name="amt"><br>
Select Conversion Type
<input type="radio" name="type" value="r2d" checked>Rupees to Dollar
<input type="radio" name="type" value="d2r">Dollar to Rupees<br>
<input type="reset"><input type="submit" value="CONVERT">
</form>
</body>
</html>
CC Bean
package MyBean;
import [Link];
/**
*
* @author spdc
*/
@Stateless
public class CCBean implements CCBeanLocal {
@Override
public double d2Rupees(double d) {
throw new UnsupportedOperationException("Not supported yet."); //To change
body of generated methods, choose Tools | Templates.
}
}
/*
* 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.
*/
CCBeanLocal
package MyBean;
import
[Link];
/**
*
* @author spdc
*/
@Local
public interface CCBeanLocal {
CCServlet
/*
* 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.
*/
package MyPack;
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
import [Link].*;
import
[Link].*;
import [Link].*;
import
[Link];
import [Link];
/**
*
* @author spdc
*/
public class beanServlet extends HttpServlet
{ @EJB CCBeanLocal obj;
/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
/* TODO output your page here. You may use following sample code. */
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo()
{ return "Short description";
}// </editor-fold>
Output :-
Source Code :-
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>Room Reservation</title>
</head>
<body>
<form method="post" action="RoomsClient">
<br> No of Rooms <input type=text name="t1">
<br> <input type="submit" name="btn" value="CheckIN">
<br> <input type="submit" name="btn" value="CheckOUT">
</form>
</body>
</html>
BhanduBeans
package MyBeans;
import
[Link];
import [Link].*;
@Stateless
public class BhanduBeans implements BhanduBeansLocal {
@Override
public int checkin(int no) {
try
{
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
[Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost:3306/mysql","root","1234
5");
String sql1 = "select * from room";
Statement
st=[Link](); ResultSet
rs=[Link](sql1); [Link]();
int
total=[Link](1);
int occ=[Link](2);
int free=total-occ;
[Link](total);
[Link](free);
if (free>=no)
{
String sql2="update room set occ=?";
PreparedStatement
ps=[Link](sql2); [Link](1,
occ+no);
int
res=[Link]();
return res;
}
else return 0;
}
catch(Exception e)
{
return 0;
}
}
@Override
public int checkout(int no) {
try
{ [Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost/roomdb","root","tiger");
String sql1 = "select * from room";
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
Statement
st=[Link](); ResultSet
rs=[Link](sql1);
[Link]();
int
total=[Link](1);
int occ=[Link](2);
if (occ>=no)
{
String sql2="update room set occ=?";
PreparedStatement
ps=[Link](sql2); [Link](1, occ-
no);
int
res=[Link]();
return res;
}
else return 0;
}
catch(Exception e)
{
return 0;
}
}
}
BhanduBeansLocal
/*
* 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.
*/
package MyBeans;
import
[Link];
@Local
public interface BhanduBeansLocal
{
public int checkin(int no);
public int checkout(int no);
}
Room [Link]
package mypack;
import
[Link];
import [Link].*;
import [Link];
import [Link].*;
import
[Link].*;
import [Link].*;
@WebServlet(name = "roomclient", urlPatterns = {"/roomclient"})
public class RoomsClient extends HttpServlet {
@EJB BhanduBeansLocal obj;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html");
PrintWriter out =
[Link](); try {
int no=[Link]([Link]("t1"));
String b=[Link]("btn");
int res=0;
if([Link]("CheckIN"))
{
res=[Link](no);
//if (res==1)
[Link](no + " rooms check-in");
}
if([Link]("CheckOUT"))
{
res=[Link](no);
//if (res==1)
[Link](no + " rooms check-out");
}
//if(res==0)
[Link]("Not possible to do Check IN / OUT");
[Link]("<br><br><a href=[Link]> Back </a>");
}
finally {
[Link]();
}
}
}
Output :-
Practical No.7
[Link]
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Refresh" content="0; URL=ServletClient">
</head>
<body>
<div>TODO write content</div>
</body>
</html>
[Link]
package ejb;
import
[Link];
@Singleton
public class CountServletHitsBean
{ private int hitCount;
public synchronized int getCount()
{
return hitCount++;
}
}
[Link]
package servlet;
import [Link];
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
import [Link].*;
import
[Link];
import [Link];
import [Link];
import [Link].*;
@WebServlet(name = "ServletClient", urlPatterns = {"/ServletClient"})
public class ServletClient extends HttpServlet {
@EJB CountServletHitsBean obj;
@Override
protected void service (HttpServletRequest req, HttpServletResponse res) throws
ServletException,
IOException
{
[Link]("text/html");
PrintWriter out=[Link]();
[Link]("<b>Number of times this Servlet is accessed </b>: "+[Link]());
}
}
Output :-
Source Code :-
[Link]
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%!
private static ConnectionFactory connectionFactory;
private static Queue queue;
Connection
connection=null; Session
mySession=null;
MessageProducer
messageProducer=null; TextMessage
message=null;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
Welcome to My Home Page
<%
try{
InitialContext ic= new InitialContext();
queue=
(Queue)[Link]("jms/Queue");
connectionFactory=(ConnectionFactory)[Link]("jms/QueueFactory");
connection= [Link]();
mySession=[Link](false,
Session.AUTO_ACKNOWLEDGE);
messageProducer=[Link](queue);
message=[Link]();
[Link]([Link]());
[Link](message);
}
catch(JMSException e)
{
[Link]("Exception Occoured "+[Link]());
}
%>
</body>
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
</html>
Firstvisitdt – timestamp
}
}
@PreDestroy
public void disconnect()
{
try {
[Link]();
} catch (Exception e) { [Link]([Link]());
}
}
public void addVisitor(String host)
{
try {
st= [Link]();
query="insert into userstat (hostname,visits) values ('"+host+"','1')";
[Link](query);
}
catch (SQLException e)
{
try {
st=[Link]();
query="update userstat set visits=visits+1 where hostname='"+host+"' ";
[Link](query);
}
catch (SQLException ex) {
[Link]("Cannot Update"+[Link]());
}
}
}
}
Step 4: Right click on Source Packages à Select Newà Otherà Enterprise Java
Bean
package ejb;
import [Link];
import [Link];
import [Link];
@MessageDriven(activationConfig = {
"[Link]")
})
@Resource
@Override
}
Step 5:
Find Admin Object Resources and double click on that -> click on ‘New’ Button
-> write JNDI name as -> jms/Queue.
Output :-
Practical No.8
[Link] a Hibernate application to store Feedback of Website Visitor in
MySQL Database.
Hibernate – Feedback of Website Visitor (on index paper)
Select Services -> right click on database -> connect -> password -> ok ->again
right click on database -> create database -> db -> ok.
Expand db -> Select and right click table -> click on Execute command ->
Create table guestbook (no int primary key auto_increment, name varchar(20), msg
varchar(100), dt varchar(40));
File -> New Project -> Java Web -> Web application - > Next -> give
the project name -> browse the location as required -> select the
checkbox – “dedicated folder for storing libraries” -> Next
Select glassfish server -> next
Select frame work - hibernate -> select the respective database connection ->
finish.
Right click on Project -> new -> other -> select Hibernate -> Hibernate
Reverse Engineering wizard file type -> next -> file name
([Link]) , folder -> click on browse and select src->java -> next
-> select guestbook table name from the available tables option -> click
add ( select the checkbox – include related files) -> finish.
Step 4: Adding Hibernate mapping files and POJOs from Database file type:-
Right click on Project -> new -> other -> select Hibernate -> Hibernate
mapping files and POJOs from Database file type) -> next -> keep the
default configuration file name file name ([Link]) and Hibernate
Reverse Engineering File ([Link]) -> type the package name
(hibernate) -> finish.
Right click on project -> new -> JSP -> filename -> guestbookview ->
select radiobutton -> JSP file (Standard syntax) -> Finish.
Source Code :-
package hibernate;
private String name; private String msg; private String dt; public Guestbook() {
{ [Link] = name;
[Link]
<hibernate-configuration>
<session-factory>
<property name="[Link]">[Link]</property>
<property
name="[Link].driver_class">[Link]</property>
<property
name="[Link]">jdbc:mysql://localhost:3306/db</property>
<property name="[Link]">root</property>
<property name="[Link]">tiger</property>
<mapping resource="hibernate/[Link]"/>
</session-factory>
[Link]
<hibernate-mapping>
</id>
</property>
</property>
</property>
</class>
</hibernate-mapping>
[Link]
<html>
<head>
<title>Guest Book</title>
</head>
<body>
</form>
</body>
</html>
[Link]
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%@page import="[Link]"%>
<%!
%>
<%
Transaction tx=null;
tx=[Link]();
[Link](msg);
[Link](dt); [Link](gb);
[Link]();
catch(Exception e){ }
%>
<html>
<head>
<title>Guest View</title>
</head>
<body>
Guest
View
<br><br>
{
Teacher Name : [Link] Rongare
TY BSC-IT Sem-V Roll No :- 04
Advance Java Name : Ashish Bhandari
%>
</body>
</html>
Output :-