0% found this document useful (0 votes)
80 views

Q.1) Create A Web Application To Implement Servlet Lifecycle Using Servlet Interface. Ans 1)

The document discusses implementing servlet lifecycle and generic servlets in Java. It provides code for a servlet that implements the servlet lifecycle methods init(), service(), and destroy(). It also provides code for a generic servlet that handles form submission from a registration page and validates the input fields. Finally, it shows code for an HTTP servlet that implements a page hit counter.

Uploaded by

Anonymous SS9w0L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
80 views

Q.1) Create A Web Application To Implement Servlet Lifecycle Using Servlet Interface. Ans 1)

The document discusses implementing servlet lifecycle and generic servlets in Java. It provides code for a servlet that implements the servlet lifecycle methods init(), service(), and destroy(). It also provides code for a generic servlet that handles form submission from a registration page and validates the input fields. Finally, it shows code for an HTTP servlet that implements a page hit counter.

Uploaded by

Anonymous SS9w0L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 39

giBS 01619114416

Q.1) Create a web application to implement Servlet Lifecycle using Servlet interface.

Ans 1)

Lifecyclenormal.java

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.Servlet;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.*;

public class Lifecyclenormalimplements Servlet{

public void destroy()

{System.out.println("DESTROY");

public void init(ServletConfig config)throws ServletException

{System.out.println("INIT");

public void service(ServletRequestreq,ServletResponse res)throws ServletException,IOException

System.out.println("SERVICE");

PrintWriter out=res.getWriter();

out.print("<h1>Servelt Life Cycle Implementation</h1>");

out.print("<h2>Servelt Life Cycle Implementation</h2>");

public ServletConfiggetServletConfig()

return null;
giBS 01619114416

public String getServletInfo()

return null;

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

<servlet>

<servlet-name>VIJ</servlet-name>

<servlet-class>Lifecyclenormal</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>VIJ</servlet-name>

<url-pattern>/Lifecyclenormal</url-pattern>

</servlet-mapping>

<session-config>

<session-timeout>

30

</session-timeout>

</session-config>

</web-app>
giBS 01619114416

Output1:
giBS 01619114416

Ques 2) Show the implementation of Generic Servlet by creating a simple registration


page.

Ans 2)

Index.html

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<h1 center > Registration form</h1>

<Form action="Validation">

Name: <input type="text" name="name" ><br/>

Email: <input type="email" name="Email" /><br>

Password: <input type="password" name="Password" ><br>

Phone no.:<input type="number" name="Phonenumber" value=""/><br>

Gender:

Male <input type="radio" name="Gender" value="MALE" checked=""/>

Female <input type="radio" name="Gender" value="FEMALE"/><br/>

Hobbies:

Programming <input type="checkbox" name="Hobbies" value="Writing" /><br>

Playing <input type="checkbox" name="Hobbies" value="Dancing" /><br>

Reading <input type="checkbox" name="Hobbies" value="Reading" /><br/>

Course <select name="Course">

<option>MCA</option>

<option>BCA</option>

<option>MCADD</option>

</select><br>
giBS 01619114416

<input type="Submit" name="Submit" value="Submit" />

<input type="submit" name="Cancel" value="Cancel" />

</form>

</body>

</html>Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

<servlet>

<servlet-name>VIJ1</servlet-name>

<servlet-class>Validation</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>VIJ1</servlet-name>

<url-pattern>/Validation</url-pattern>

</servlet-mapping>

<session-config>

<session-timeout>

30

</session-timeout>

</session-config>

</web-app>

Validation.java

import java.io.IOException;
giBS 01619114416

import java.io.PrintWriter;

import javax.servlet.GenericServlet;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

public class Validation extends GenericServlet

private String number;

@Override

public void service(ServletRequest req, ServletResponse res) throws ServletException,


IOException {

PrintWriter out=res.getWriter();

String name=req.getParameter("Vijender");

String Email=req.getParameter("Email");

String Password=req.getParameter("Password");

String Phonenumber=req.getParameter("Phonenumber");

String gender=req.getParameter("Gender");

String hobbies[]=req.getParameterValues("Hobbies");

String Course=req.getParameter("Course");

if(name.equals("")||Password.equals("")||Email.equals("")||Phonenumber.equals(""))

RequestDispatcherrd= req.getRequestDispatcher("index.jsp");

rd.forward(req, res);

else

{out.println(name);

out.println(Email);
giBS 01619114416

out.println(Password);

out.println(Phonenumber);

out.println(gender);

for(int i=0;i<hobbies.length;i++)

out.println(hobbies[i]);

out.println(Course);

Output2:
giBS 01619114416

Ques 3) Create a web application using Http Servlet to implement page hit counter.

Ans 3)

Counter.java

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletContext;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class Counter1 extends HttpServlet {

@Override

public void init()

ServletContext context=getServletConfig().getServletContext();

context.setAttribute("count",0);

@Override

public void doGet(HttpServletRequestreq,HttpServletResponse res)throws IOException{

ServletContext context=getServletConfig().getServletContext();

int count=(Integer)context.getAttribute("count");

count++;

PrintWriter out=res.getWriter();

out.println("<h1>You have visited the site:</h1>");

out.println("<h1>");

out.println(count);

out.println("</h1>");

context.setAttribute("count",count);

}
giBS 01619114416

public void doPost(HttpServletRequestreq,HttpServletResponse res)throws IOException{

doGet(req,res);

Index.html

<!DOCTYPE html>

<html>

<head>

<title>Counter</title>

</head>

<body>

<h1> You have visited: </h1>

</body>

</html>

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

<servlet>

<servlet-name>Counter1</servlet-name>

<servlet-class>Counter1</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Counter1</servlet-name>

<url-pattern>/count</url-pattern>

</servlet-mapping>
giBS 01619114416

<session-config>

<session-timeout>

40

</session-timeout>

</session-config>

</web-app>

Output3:
giBS 01619114416

Ques 4) Create a web application containing a login page and perform validation(using
servlet Config and request dispatcher).

Ans 4)

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<servlet>

<servlet-name>login</servlet-name>

<servlet-class>login</servlet-class>

<init-param>

<param-name>Uname</param-name>

<param-value>admin </param-value>

</init-param>

<init-param>

<param-name>Upassword</param-name>

<param-value>admin123</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>login</servlet-name>

<url-pattern>/login</url-pattern>

</servlet-mapping>

<session-config>

<session-timeout>

30

</session-timeout>

</session-config>

</web-app>

Login.java

import java.io.IOException;
giBS 01619114416

import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class login extends HttpServlet{

@Override

public void doPost(HttpServletRequestreq,HttpServletResponse res) throws


IOException,ServletException{

res.setContentType("text/html");

String Uname=req.getParameter("Name");

String Password=req.getParameter("Password");

String Uname=getServletConfig().getInitParameter("Uname");

String Upassword=getServletConfig().getInitParameter("Upassword");

PrintWriter out=res.getWriter();

if(uname.equals(Uname)&&Password.equals(Upassword))

out.println(uname + "Logged in");

else

out.print("Invalid Username OR Password");

RequestDispatcherrd=req.getRequestDispatcher("index.jsp");

rd.include(req, res);

public void doGet(HttpServletRequestreq,HttpServletResponse res)throws


IOException,ServletException{
giBS 01619114416

doPost(req,res);

Index.jsp

<%@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>Login</h1><form action="login">

Name <input type="text" name="Name" value="" /><br/>

Password <input type="password" name="Password" value=""/><br>

<input type="Submit" name="Submit" value="Submit" />

<input type="submit" name="Cancel" value="Cancel" />

</form>

</body>

</html>
giBS 01619114416

Output:
giBS 01619114416

Ques 5) Create a web application to show session management: Hidden fields technique
by creating a simple shopping application.

INDEX.html

<%@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>WELCOME!</h1>

<form action="First” method="post">

<input type="checkbox" name="id" value="SHIRTS">SHIRT<br/>

<input type="checkbox" name="id" value="TSHIRTS">TSHIRT<br/>

<input type="checkbox" name="id" value="PANTS">PANTS<br/>

<input type="submit" value="submit">

</form>

</body>

</html>

First.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class First extends HttpServlet{

protected void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException,


IOException{

PrintWriter out=res.getWriter();

String id[]=req.getParameterValues("id");
giBS 01619114416

out.println("<form action='Second'>");

for(int i=0;i<id.length;i++)

out.println("<input type='hidden' name='id' value='"+id[i]+"'>");

out.println("<input type='checkbox' name='id1' value='d'>d");

out.println("<input type='checkbox' name='id1' value='e'>e");

out.println("<input type='checkbox' name='id1' value='f'>f");

out.println("<input type='submit' value='submit'>");

out.println("</form>");

SERVLET(Second)

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Second extends HttpServlet{

protected void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,


IOException{

PrintWriter out=res.getWriter();

String id[]=req.getParameterValues("id");

for(int i=0;i<id.length;i++)

out.println(id[i]);

String id1[]=req.getParameterValues("id1");

for(int j=0;j<id1.length;j++)
giBS 01619114416

out.println(id1[j]);

Web

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

<session-config>

<session-timeout>

30

</session-timeout>

</session-config>

<servlet>

<servlet-name>First</servlet-name>

<servlet-class>First</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>First</servlet-name>

<url-pattern>/First</url-pattern>

</servlet-mapping>
giBS 01619114416

<servlet>

<servlet-name>Second</servlet-name>

<servlet-class>Second</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Second</servlet-name>

<url-pattern>/Second</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>
giBS 01619114416

Output5:
giBS 01619114416

Ques 7) Create a web application showing the use of JSP implicit objects.

JSP request implicit object

Welcome.jsp

<% String name=request.getParameter("uname");

out.println("HELLO "+name);

%>

Newhtml.html

<form action="welcome.jsp">

<input type="text" name="uname">

<input type="submit" value="go"><br/>

</form>

OUTPUT7a:

JSP Response implicit object

test.html

<html>

</head>
giBS 01619114416

<body>

<h1> welcome to my page <br/>

visit again

</body>

</html>

Welcome.jsp

<% response.sendRedirect("thanks.html"); %>

Index.html

<form action="welcome.jsp">

<input type="text" name="uname">

<input type="submit" value="go"><br/>

</form>

OUTPUT7b:

JSP OUT Implicit object

Index.jsp

<html>

<body>

<% out.print("Today is:"+java.util.Calendar.getInstance().getTime());%>

</body>

</html>

OUTPUT7c:
giBS 01619114416

JSP EXCEPTION IMPLICIT OBJECT

JSP 1(ERROR)

<%@ page isErrorPage="true"%>

<h3>Sorry an exception occurred!</h3>

Exception is:<%=exception%>

JSP2(INDEX)

<%@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>

<form action="process.jsp">

No.1<input type="text" name="n1" /><br/><br/>

No.2<input type="text" name="n2" /><br/><br/>

<input type="submit" value="divide" />

</form>
giBS 01619114416

</body>

</html>

JSP 3(PROCESS)

<%@ page errorPage="error.jsp"%>

<%

String num1=request.getParameter("n1");

String num2=request.getParameter("n2");

int a=Integer.parseInt(num1);

int b=Integer.parseInt(num2);

int c=a/b;

out.print("division of number is"+" "+"="+c);

%>

OUTPUT7d:
giBS 01619114416

JSP APPLICATION IMPLICIT OBJECT

Index.html

<form action="welcome">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>

Web.xml

<web-app>

<servlet>
<servlet-name>sonoojaiswal</servlet-name>
<jsp-file>/welcome.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>sonoojaiswal</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>

<context-param>
<param-name>dname</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</context-param>

</web-app>

Welcome.jsp

<%

out.print("Welcome "+request.getParameter("uname"));

String driver=application.getInitParameter("dname");
out.print("driver name is="+driver);

%>
giBS 01619114416

OUTPUT7e:
giBS 01619114416

Ques 8) Create a web application to show session management: Session interface


technique by creating login-logout interfaces in JSP.

INDEX.HTML

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<h1>Login App using HttpSession</h1>

<a href="login.html">Login</a>

<a href="LogoutServlet">Logout</a>

<a href="ProfileServlet">Profile</a>

</body>

</html>

Link

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<a href="login.html">Login</a>

<a href="LogoutServlet">Logout</a>

<a href="ProfileServlet">Profile</a>

<hr>

</body>

</html>
giBS 01619114416

Log in

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<form action="LoginServlet" method="post">

Name:<input type="text" name="name"><br>

Password:<input type="password" name="password"><br>

<input type="submit" value="login">

</form>

</body>

</html>

LoginServlet

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;

public class LoginServlet extends HttpServlet{

protected void doPost(HttpServletRequest request, HttpServletResponse response)throws


ServletException, IOException{

response.setContentType("text/html");

PrintWriter out=response.getWriter();

request.getRequestDispatcher("link.html").include(request,response);
giBS 01619114416

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

String password=request.getParameter("password");

if(password.equals("admin123")){

out.println("");

out.print("Welcome" +" "+ name);

HttpSession session=request.getSession();

session.setAttribute("name", name);

else{

out.print("Sorry, username or password error");

request.getRequestDispatcher("login.html").include(request, response);

out.close();

LogoutServlet

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;
giBS 01619114416

import javax.servlet.http.HttpSession;

public class LogoutServlet extends HttpServlet {

protected void doGet(HttpServletRequestrequest,HttpServletResponse response) throws


ServletException,IOException{

response.setContentType("text/html");

PrintWriter out=response.getWriter();

request.getRequestDispatcher("link.html").include(request, response);

HttpSession session=request.getSession();

session.invalidate();

out.print("You are successfully logged out");

out.close();

ProfileServlet

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;

import javax.servlet.http.HttpSession;
giBS 01619114416

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

public class ProfileServlet extends HttpServlet {

protected void doGet(HttpServletRequestrequest,HttpServletResponse response)throws


ServletException,IOException{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

request.getRequestDispatcher("link.html").include(request,response);

HttpSession session=request.getSession(false);

if(session!=null)

String name=(String)session.getAttribute("name");

out.print("hello,"+" "+ name+" "+"welcome to profile");

else

out.print("please login first");

request.getRequestDispatcher("login.html").include(request, response);

out.close();

}
giBS 01619114416

Xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

<session-config>

<session-timeout>

30

</session-timeout>

</session-config>

<servlet>

<description></description>

<display-name>LoginServlet</display-name>

<servlet-name>LoginServlet</servlet-name>

<servlet-class>LoginServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>LoginServlet</servlet-name>

<url-pattern>/LoginServlet</url-pattern>

</servlet-mapping>

<servlet>

<description></description>

<display-name>ProfileServlet</display-name>
giBS 01619114416

<servlet-name>ProfileServlet</servlet-name>

<servlet-class>ProfileServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>ProfileServlet</servlet-name>

<url-pattern>/ProfileServlet</url-pattern>

</servlet-mapping>

<servlet>

<description></description>

<display-name>LogoutServlet</display-name>

<servlet-name>LogoutServlet</servlet-name>

<servlet-class>LogoutServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>LogoutServlet</servlet-name>

<url-pattern>/LogoutServlet</url-pattern>

</servlet-mapping>

</web-app>
giBS 01619114416

OUTPUT 8:

Home Page:

LOGIN APPLICATION USING HttpSession

Login Logout Profile

LoginPage

Hello, Zeeshan welcome

Profile:

Hello, Zeeshan welcome to profile

Logout

You have successfully logged out

Error Page
giBS 01619114416

Ques 9) Create a web application to show error handling technique in JSP.

JSP 1(ERROR)

<%@ page isErrorPage="true"%>

<h3>Sorry an exception occurred!</h3>

Exception is:<%=exception%>

JSP2(INDEX)

<%@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>

<form action="process.jsp">

No.1<input type="text" name="n1" /><br/><br/>

No.2<input type="text" name="n2" /><br/><br/>

<input type="submit" value="divide" />

</form>

</body>

</html>

JSP 3(PROCESS)

<%@ page errorPage="error.jsp"%>

<%

String num1=request.getParameter("n1");

String num2=request.getParameter("n2");

int a=Integer.parseInt(num1);

int b=Integer.parseInt(num2);
giBS 01619114416

int c=a/b;

out.print("division of number is"+" "+"="+c);

%>

OUTPUT:
giBS 01619114416

Ques 10) Create a web application to show use of Java Bean in JSP.

JSP(INDEX)

<%@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>

<form action="displaydetails.jsp">

Name:

<input type="text" name="txtname"><br>

Password:

<input type="password" name="txtpass"><br>

Gender:<br>

<input type="radio" name="gender" value="Male">Male<br>

<input type="radio" name="gender" value="Female">Female<br>

<input type="submit" name="submit" value="submit">

</form>

</body>

</html>

JSP(DISPLAY)

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

<!DOCTYPE html>

<html>

<head>
giBS 01619114416

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<jsp:useBean id="id1" class="pkg.mybean"></jsp:useBean>

<jsp:setProperty name="id1" property= "*"></jsp:setProperty>

Details are:

<jsp:getProperty name="id1" property="txtname"></jsp:getProperty><br/>

<jsp:getProperty name="id1" property="txtpass"></jsp:getProperty><br/>

<jsp:getProperty name="id1" property="gender"></jsp:getProperty><br/>

</body>

</html>

BEAN CLASS

package pkg;

public class mybean {

private String txtname, txtpass, gender;

public String getTxtname() {

return txtname;

public void setTxtname(String txtname) {

this.txtname = txtname;

public String getTxtpass() {

return txtpass;

public void setTxtpass(String txtpass) {

this.txtpass = txtpass;

}
giBS 01619114416

public String getGender() {

return gender;

public void setGender(String gender) {

this.gender = gender;

}
giBS 01619114416

OUTPUT10:

You might also like