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

Web Technology Lab File-5

The document discusses a web technology lab file submitted by a student. It contains an index of various programs completed by the student as part of the lab work. The programs cover topics like HTML, CSS, Java, databases and more.

Uploaded by

ananyasingh15803
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Web Technology Lab File-5

The document discusses a web technology lab file submitted by a student. It contains an index of various programs completed by the student as part of the lab work. The programs cover topics like HTML, CSS, Java, databases and more.

Uploaded by

ananyasingh15803
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

WEB TECHNOLOGY LAB FILE

Submitted To

Ajay Kumar Garg Engineering College, Ghaziabad

B.Tech. Information Technology


Sem-5th
2023-24
CODE: KIT-551

Submitted By:- Submitted To:-


Ananya Singh Mr. SantoshMishra
(2100270130044)

Dr. A.P.J. Abdul Kalam Technical University, Uttar Pradesh,


Lucknow
INDEX

S.N Practical Name Practical Submission Signature Remarks


o Date Date

1.
Write HTML/Java scripts to display your CV in
navigator, your Institute website, Department
Website and Tutorial website for specific subject

2.
Write a java program to create a Box class having
attributes of Box and volume and area methods.
Initialize these attributes using default,
parameterized and copy constructor. Create object
for three different boxes and display volume and
area of these boxes.

3.
Write a program in java to explain this, static, super
and final keywords.

4.
Implement multilevel and multiple inheritances in
java.

5.
Write a java Program to implement method
overloading and method overriding

6.
Write a java program to explain tries, catch, throw
and throws keywords.

7.
Write a program in java to create a package and
import it.

8.
Write a program in java to implement
multithreading.

9.
Write a program to create a frame window that
contains two text box and a button named
swap. The text in the text boxes should interchange
after clicking on swap.

10.
Write an HTML program to design an entry form of
student details and apply suitable CSS. Also
apply required validations in the form fields.

11.
Writing program in XML for creation of DTD,
which specifies a set of rules. Create a style sheet in
CSS/ XSL & display the document in internet
explorer.

12.
Program to illustrate JDBC connectivity. Program
for maintaining database by sending queries.

13.
Install TOMCAT web server and APACHE. Access
any developed static web pages using these
servers by putting the web pages developed.

14.
Install a database (Mysql or Oracle). Create a table
which should contain at least the following
fields: name, password, email-id, phone number
Write a java program/servlet/JSP to connect to that
database and extract data from the tables and display
them. Insert the details of the users who register with
the web site, whenever a new user clicks the submit
button in the registration page.

15.
Write a JSP which insert the details of the 3 or 4
users who register with the web site by using
registration form. Authenticate the user when he
submits the login form using the user name and
password from the database.
Program-1

Program Name: Write HTML/Java scripts to display your CV in navigator,


your Institute website, Department Website and Tutorial website for specific
subject

Code:
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div><a
href="https://docs.google.com/document/d/1vEvNEM1yDAVK2vxsqZ79RkcidAeUopC2QHw
ahnxF_3o/edit?usp=sharing">CV</a></div>
<div><a href="https://www.akgec.ac.in">Institute Website</a></div>
<div><a
href="https://www.akgec.ac.in/departments/information-technology/">Department
Website</a></div>
<div><a
href="https://www.youtube.com/channel/UCxs6M6Um-IYd9eD3XUHRlkg/playlists">Tutorial
Website</a></div>
</div>
</body>
</html>

style.css
.container{
display: flex;
justify-content: space-between;
align-items: center;
color: rgb(1, 0, 0);
background-color: aqua;
font-size: 2em;
}
body{

Ananya Singh 2100270130032 IT-1


SSSSingh
background-color: darkgray;
}
a:link {
text-decoration: none;
}

Output:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-2

Program name: Write a java program to create a Box class having


attributes of Box and volume and area methods. Initialise these
attributes using default, parameterized and copy constructor. Create
objects for three different boxes and display the volume and area of
these boxes.

Code:
class Box {
double length;
double width;
double height;
public Box() {}
public Box(double l, double b, double h) {
this.length = l;
this.width = b;
this.height = h;
}
Box(Box copyBox) {
this.length = copyBox.length;
this.width = copyBox.width;
this.height = copyBox.height;
}
void getVolume() {
System.out.println("Volume is:"+length*width*height);
}
void getSurfaceArea() {
System.out.println("Surface Area is:"+2 * (length * width + width * height + height * length));
}
}
public class Main {
public static void main(String[] args) {
Box box1 = new Box();
Box box2 = new Box(3.0, 4.0, 5.0);
Box box3 = new Box(box2);
box1.getSurfaceArea();

Ananya Singh 2100270130032 IT-1


SSSSingh
box1.getVolume();
box2.getSurfaceArea();
box2.getVolume();
box3.getSurfaceArea();
box3.getVolume();
}
}

Output:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-3

Program name: Write a program in java to explain this, static, super and
final keywords.

Code:
Super
class Animal {
String color = "white";
}
class Dog extends Animal {
String color = "black";
void printColor() {
System.out.println(color);
System.out.println(super.color);
}}
class TestSuper1 {
public static void main(String args[]) {
Dog d = new Dog();
d.printColor();
}}

Output:

Super
class Test {
static int x=10;
public static void main (String args[]) {
System.out.println ("x=" +Test.x);
}}

Output:

Final

Ananya Singh 2100270130032 IT-1


SSSSingh
class Third {
final int x = 10;
public static void main(String[] args) {
Third myObj = new Third();
myObj.x = 25;
System.out.println(myObj.x);
}
}

Output:

This
class Volume {
int l,b,h;
Volume (int l, int b, int h)
{
this.l=l;
this.b=b;
this.h=h;
}
public static void main (String[] args)
{
Volume v1= new Volume(10,10,10);
System.out.println("Length ="+v1.l);
System.out.println("Breadth ="+v1.b);
System.out.println("Height ="+v1.h);
}
}

Output:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-4

Program name: Implement multilevel and multiple inheritances in java.


Code:
Multiple Inheritance

interface bark {
void barks();
}
interface meow {
void meoww();
}
class Dog implements bark {
public void barks() {
System.out.println("Dog can bark");
}
}
class cat implements meow {
public void meoww() {
System.out.println("cat can meow");
}
}
class Animal implements bark, meow {
public void barks() {
System.out.println("Animal can bark");
}
public void meoww() {
System.out.println("Animal can meow");
}
}
public class Main {
public static void main(String[] args) {
Dog Dog = new Dog();
Dog.barks();
cat cat = new cat();
cat.meoww();
Animal Animal = new Animal();
Animal.barks();
Animal.meoww();
}
}

Ananya Singh 2100270130032 IT-1


SSSSingh
OUTPUT:

Multilevel Inheritance
class Parent {
void parentMethod() {
System.out.println("This is the parent method.");
}
}
class Child extends Parent {
void childMethod() {
System.out.println("This is the child method.");
}
}
class Grandchild extends Child {
void grandchildMethod() {
System.out.println("This is the grandchild method.");
}
}
public class Main {
public static void main(String[] args) {
Grandchild obj = new Grandchild();
obj.parentMethod();
obj.childMethod();
obj.grandchildMethod();
}
}

Output:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-5

Program name: Write a java Program to implement method overloading


and method overriding.
Code:

Method overloading

public class Overloading {


public static void main(String args[]){
addition n=new addition();
System.out.println("This is int function"+n.add(2,4));
System.out.println("This is a float function"+n.add(10.1, 13.6));
}
}
class addition{
public int add(int a, int b){
return a+b;
}
public double add(double x,double y){
return x+y;
}
}

Output

Ananya Singh 2100270130032 IT-1


SSSSingh
Method overriding
class Parent {
public void display() {
System.out.println("This is the Parent class");
}
}
class Child extends Parent {
public void display() {
System.out.println("This is the Child class");
}
}
public class Main1{
public static void main(String args[]){
Child c1=new Child();
c1.display();
}
}

Output

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-6

Program name: Write a java program to explain tries, catch, throw and
throws keywords.

Code:
public class ExceptionHandlingExample {

public static void main (String [] args) {


try {
int result = divide (10, 0);
System.out.println("Result of the division: " + result);
} catch (ArithmeticException e) {
System.out.println("An error occurred: " + e.getMessage());
}
System.out.println("Program continues...");
}

public static int divide (int dividend, int divisor) throws ArithmeticException {
if (divisor == 0) {
throw new ArithmeticException("Division by zero is not allowed.");
}
return dividend / divisor;
}
}
Output

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-7

Program name: Write a program in java to create a package and import it.

Code:
//Package file
package mypackage;
public class Main2 {
public static void HI(){
System.out.println("Hello World");
}
}

//Importing package
import mypackage.Main2;
public class Main1 {
public static void main(String[] args) {
Main2.HI();
}
}

Output:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-8

Program name: Write a program in java to implement multithreading.


Code:
public class threadsexample extends Thread {
public static void main(String[] args){
threadsexample t1=new threadsexample();
threadsexample t2=new threadsexample();
threadsexample t3=new threadsexample();
t1.run();
t2.run();
t3.run();
}
}

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-9

Program name: Write a program to create a frame window that contains two
text box and a button named swap. The text in the text boxes should interchange
after clicking on swap.
Code:
/*<applet code="MyWindow2" width="400" height="500"></applet>*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MyWindow2 extends Applet implements ActionListener{
Label l1,l2;
TextField t1,t2;
Button c;
public void init(){
l1=new Label("Text1:");
t1=new TextField();
l2=new Label("Text2:");
l1.setBounds(10,10,80,30);
t1.setBounds(90,10,80,30);
l2.setBounds(10,40,80,30);
t2=new TextField();
t2.setBounds(90,40,80,30);
c=new Button("Copy");
c.setBounds(10,80,80,30);
c.addActionListener(this);
add(l1);add(t1);add(l2);add(t2);add(c);
setLayout(null);}
public void actionPerformed(ActionEvent e){
if(e.getSource()==c){
String s=t1.getText();
String s2=t.getText();
t2.setText(s);
t1.setText(s2);
}
}}

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-10

Program name: Write an HTML program to design an entry form of student


details and apply suitable CSS. Also apply required validations in the form
fields.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 400px;
margin: 50px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 8px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4caf50;
color: #fff;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.error {

Ananya Singh 2100270130032 IT-1


SSSSingh
color: #ff0000;
margin-bottom: 8px;
}
</style>
<script>
function validateForm() {
var name = document.forms["studentForm"]["name"].value;
var email = document.forms["studentForm"]["email"].value;
if (name === "") {
alert("Name must be filled out");
return false;
}
if (email === "") {
alert("Email must be filled out");
return false;
}
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
alert("Invalid email address");
return false;
}
}
</script>
</head>
<body>
<div class="container">
<form name="studentForm" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob">
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>

Ananya Singh 2100270130032 IT-1


SSSSingh
OUTPUT:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-11

Program name: Writing program in XML for creation of DTD, which


specifies set of rules. Create a style sheet in CSS/ XSL & display the document
in internet explorer
CODE:
Books.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="Rule.css"?>
<books>
<heading>Welcome To GeeksforGeeks </heading>
<book>
<title>Title -: Web Programming</title>
<author>Author -: Chrisbates</author>
<publisher>Publisher -: Wiley</publisher>
<edition>Edition -: 3</edition>
<price> Price -: 300</price>
</book>
<book>
<title>Title -: Internet world-wide-web</title>
<author>Author -: Ditel</author>
<publisher>Publisher -: Pearson</publisher>
<edition>Edition -: 3</edition>
<price>Price -: 400</price>
</book>
<book>
<title>Title -: Computer Networks</title>
<author>Author -: Foruouzan</author>
<publisher>Publisher -: Mc Graw Hill</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 700</price>
</book>
<book>
<title>Title -: DBMS Concepts</title>
<author>Author -: Navath</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 5</edition>
<price>Price -: 600</price>
</book>
<book>
<title>Title -: Linux Programming</title>
<author>Author -: Subhitab Das</author>
<publisher>Publisher -: Oxford</publisher>
<edition>Edition -: 8</edition>
<price>Price -: 300</price>

Ananya Singh 2100270130032 IT-1


SSSSingh
</book>
</books>
Rule.css
books {
color: white;
background-color : gray;
width: 100%;
}
heading {
color: green;
font-size : 40px;
background-color : powderblue;
}
heading, title, author, publisher, edition, price {
display : block;
}
title {
font-size : 25px;
font-weight : bold;
}
Output

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-12

Program name: Program to illustrate JDBC connectivity. Program for


maintaining database by sending queries.
Code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SimpleJdbcExample {
private static final String JDBC_URL = "jdbc:mysql://localhost:3306/arjundb";
private static final String USER = "arjunsinghal77";
private static final String PASSWORD = "Arjun@77";
public static void main(String[] args) {
Connection connection = null;
Statement statement = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection(JDBC_URL, USER, PASSWORD);
statement = connection.createStatement();
createTable(statement);
insertData(statement);
retrieveData(statement);
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
} finally {
try {
if (statement != null) statement.close();
if (connection != null) connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
private static void createTable(Statement statement) throws SQLException {
String createTableSQL = "CREATE TABLE IF NOT EXISTS employees ("
+ "id INT AUTO_INCREMENT PRIMARY KEY,"
+ "name VARCHAR(255),"
+ "age INT)";
statement.execute(createTableSQL);
System.out.println("Table created or already exists");
}
private static void insertData(Statement statement) throws SQLException {
String insertSQL = "INSERT INTO employees (name, age) VALUES ('John Doe', 25)";
statement.executeUpdate(insertSQL);

Ananya Singh 2100270130032 IT-1


SSSSingh
System.out.println("Data inserted successfully");
}
private static void retrieveData(Statement statement) throws SQLException {
String selectSQL = "SELECT * FROM employees";
ResultSet resultSet = statement.executeQuery(selectSQL);
System.out.println("Retrieving data from the database:");
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println("ID: " + id + ", Name: " + name + ", Age: " + age);
}
}
}

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-13

Program name:Install TOMCAT web server and APACHE. Access any


developed static web pages using these servers by putting the web pages
developed.

Set the JAVA_HOME Variable

You must set the JAVA_HOME environment variable to tell Tomcat where to find Java. Failing to
properly set this variable prevents Tomcat from handling JSP pages. This variable should list the base
JDK installation directory, not the bin subdirectory.

On Windows XP, you could also go to the Start menu, select Control Panel, chooseSystem, click on
the Advanced tab, press the Environment Variables button at the bottom, and enter the JAVA_HOME
variable and value directly as:

Name: JAVA_HOME

Value: C:\jdk

Set the CLASSPATH

Since servlets and JSP are not part of the Java 2 platform, standard edition, youhave to identify the
servlet classes to the compiler. The server already knows about theservlet classes, but the compiler
(i.e., javac ) you use for development probably doesn't.So, if you don't set your CLASSPATH,
attempts to compile servlets, tag libraries, or other classes that use the servlet and JSP APIs will fail
with error messages about unknownclasses.

Name: JAVA_HOME
Value: install_dir/common/lib/servlet-api.jar

Turn on Servlet Reloading

The next step is to tell Tomcat to check the modification dates of the class files of requested servlets
and reload ones that have changed since they were loaded into theserver's memory. This slightly
degrades performance in deployment situations, so isturned off by default. However, if you fail to turn
it on for your development server,you'll have to restart the server every time you recompile a servlet
that has already beenloaded into the server's memory.

To turn on servlet reloading, edit install_dir/conf/server.xml and add a DefaultContext subelement to


the main Host element and supply true for the reloadable attribute. For example, in Tomcat 5.0.27,
search for this entry:

<Host name="localhost" debug="0" appBase="webapps" ...> and then insert the following
immediately below it:

Ananya Singh 2100270130032 IT-1


SSSSingh
<DefaultContext reloadable="true"/>

Be sure to make a backup copy of server.xm before making the above change.

Enable the Invoker Servlet

The invoker servlet lets you run servlets without first making changes to yourWeb
application's deployment descriptor. Instead, you just drop your servlet into
WEB-INF/classes and use the URL http://host/servlet/ServletName . The invoker servlet
isextremely convenient when you are learning and even when you are doing your
initialdevelopment.

To enable the invoker servlet, uncomment the following servlet and servlet-mapping elements
in install_dir/conf/web.xml. Finally, remember to make a backup copyof the original version
of this file before you make the changes.

servlet>
<servlet-name>invoker</servlet-name> <servlet-class> org.apache.catalina.servlets.InvokerServlet
</servlet-class>
...

</servlet>
... <servlet-mapping>

<servlet-name>invoker</servlet-name>

<url-pattern>/servlet/*</url-pattern> </servlet-mapping>

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-14

Program name: Install a database (Mysql or Oracle). Create a table which


should contain at least the following fields: name, password, email-id, phone
number Write a java program/servlet/JSP to connect to that database and extract
data from the tables and display them. Insert the details of the users who register
with the web site, whenever a new user clicks the submit button in the
registration page
Code:
Registration.html:
<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor="#00FFFf">
<form METHOD="POST" ACTION="register">
<CENTER>
<table>
<center>
<tr> <td> Username </td>
<td><input type="text" name="usr"> </td> </tr>
<tr><td> Password </td>
<td><input type="password" name="pwd"> </td> </tr>
<tr><td>Age</td>
<td><input type="text" name="age"> </td> </tr>
<tr> <td>Address</td>
<td> <input type="text" name="add"> </td> </tr>
<tr> <td>email</td>
<td> <input type="text" name="mail"> </td> </tr>
<tr> <td>Phone</td>
<td> <input type="text" name="phone"> </td> </tr>
<tr> <td colspan=2 align=center> <input type="submit" value="submit"> </td> </tr>
</center>
</table>
</form>
</body>

Ananya Singh 2100270130032 IT-1


SSSSingh
Login.html
<html>
<head>
<title>Registration page</title>
</head>
<body bgcolor=pink> <center> <table>
<form METHOD="POST" ACTION="authent">
<tr> <td> Username </td>
<td><input type="text" name="usr"></td> </tr>
<tr> <td> Password </td>
<td> <input type="password" name="pwd"> </td> </tr>
<tr> <td align=center colspan="2"><input type="submit" value="submit"></td> </tr>
</table> </center>
</form>
</body>
</html>

Ini.java:
import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class Ini extends GenericServlet
{
private String user1,pwd1,email1;

public void service(ServletRequest req,ServletResponse res) throws


ServletException,IOException
{
user1=req.getParameter("user");
pwd1=req.getParameter("pwd");
email1=req.getParameter("email");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{

Ananya Singh 2100270130032 IT-1


SSSSingh
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:1521:cclab","scott","
tiger");
PreparedStatement st=con.prepareStatement("insert into personal values(?,?,?,?,?,?)");
st.setString(1,user1);
st.setString(2,pwd1);
st.setString(3,"25");
st.setString(4,"hyd");
st.setString(5,email1);
st.setString(6,"21234");
st.executeUpdate();
con.close();
}
catch(SQLException s)
{ out.println("not found "+s);
}
catch(ClassNotFoundException c)
{
out.println("not found "+c);
}
}}

web.xml:
<web-app>
<servlet>
<servlet-name>init1</servlet-name>
<servlet-class>Ini</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>init1</servlet-name>
<url-pattern>/regis</url-pattern>
</servlet-mapping>
</web-app>

Ananya Singh 2100270130032 IT-1


SSSSingh
OUTPUT:

Ananya Singh 2100270130032 IT-1


SSSSingh
Program-15

Program name: Write a JSP which insert the details of the 3 or 4 users who
register with the web site by using registration form. Authenticate the user when
he submits the login form using the user name and password from the database
Code:
Register_1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Guru Registration Form</title>
</head>
<body>
<h1>Guru Register Form</h1>
<form action="guru_register" method="post">
<table style="with: 50%">
<tr>
<td>First Name</td>
<td><input type="text" name="first_name" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="last_name" /></td>
</tr>
<tr>
<td>UserName</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contact" /></td>
</tr></table>
<input type="submit" value="Submit" /></form>

Ananya Singh 2100270130032 IT-1


SSSSingh
</body>
</html>

Guru_register.java
package demotest;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class guru_register
*/
public class guru_register extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {
// TODO Auto-generated method stub
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
String username = request.getParameter("username");
String password = request.getParameter("password");
String address = request.getParameter("address");
String contact = request.getParameter("contact");

if(first_name.isEmpty() || last_name.isEmpty() || username.isEmpty() ||


password.isEmpty() || address.isEmpty() || contact.isEmpty())
{
RequestDispatcher req = request.getRequestDispatcher("register_1.jsp");
req.include(request, response);
}
else
{
RequestDispatcher req = request.getRequestDispatcher("register_2.jsp");
req.forward(request, response);
}
}
}

Ananya Singh 2100270130032 IT-1


SSSSingh
Register_2.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Guru Success Page</title>
</head>
<body>
<a><b>Welcome User!!!!</b></a>
</body>
</html>

OUTPUT:

Ananya Singh 2100270130032 IT-1


SSSSingh

You might also like