Mahatama Gandhi Mission'S College of Engg. & Technology A-9, SECTOR-62, NOIDA
Mahatama Gandhi Mission'S College of Engg. & Technology A-9, SECTOR-62, NOIDA
SUBJECT: ……………………………………………………
DATE: .……………………
<!DOCTYPE html>
<html>
<head>
<title>registartion form</title>
<style>
table, th, td { border: 1px solid black; border-collapse: collapse;
}
th, td {
padding: 5px; text-align: center;
</style>
</head>
<body>
<h1 style="text-align: center">REGISTRATION FORM</h1>
<form>
<strong>First name:</strong><br>
<input type="text" name="firstname">
<br>
<strong>Last name:</strong><br>
<input type="text" name="lastname">
<br>
<strong>Sex:</strong><br>
<input type="radio" name="male">Male<br>
<input type="radio" name="female">Female
<hr>
<strong>Username:</strong><br>
<input type="text" name="username">
<br>
<strong>Password:</strong><br>
<input type="Password" name="password">
<br>
<hr>
<table style="width:100%">
<caption style="font-size: 20px;"><strong>Educational Qualifications</strong></caption>
<tr>
<th>Course</th>
<th>Marks Obtained(%)</th>
<th>Institute Name</th>
</tr>
<tr>
<td>10th</td>
<td>95%</td>
<td>Prakriti Public School</td>
</tr>
<tr>
<td>12th</td>
<td>91%</td>
<td>Prakriti Public School</td>
</tr>
<tr>
<td>Graduation</td>
<td>Persuing</td>
<td>AKTU</td>
</tr>
</table>
<hr>
<strong>Address:</strong><br>
<textarea name="address" rows="10" cols="80"></textarea>
<br>
<hr>
<strong>Elective Subject:</strong><br>
<input type="radio" name="subject" value="Computer">Computer<br>
<input type="radio" name="subject" value="Arts">Arts<br>
<input type="radio" name="subject" value="Maths">Maths<br>
<hr>
<strong>Comment:</strong>
<textarea name="comment" rows="10" cols="40"></textarea>
<hr>
<button type="button" onclick="alert('Your form is submitted')" style="margin-left: 600px">Submit</button><input
type="reset" name="reset">
<br>
<hr>
/form>
</body>
</html>
OUTPUT:
EXPERIMENT NO.-03
Write programs using Java script for Web Page to display browsers information
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>Do not rely on it! Most browsers returns "Gecko" as product name!</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "navigator.product is " + navigator.product;
document.getElementById("demo").innerHTML = navigator.appVersion;
document.getElementById("demo").innerHTML = navigator.userAgent;
document.getElementById("demo").innerHTML = navigator.platform;
document.getElementById("demo").innerHTML = navigator.language;
document.getElementById("demo").innerHTML = navigator.onLine;
document.getElementById("demo").innerHTML = navigator.javaEnabled();
</script>
</body>
</html>
OUTPUT:
The Navigator Object
b[i]=new Button(""+i);
}
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
EQ.addActionListener(this);
}
v1=Integer.parseInt(t1.getText()); OP='*';
t1.setText("");
}
else if(str.equals("div"))
{
v1=Integer.parseInt(t1.getText()); OP='/';
t1.setText("");
}
else if(str.equals("mod"))
{
v1=Integer.parseInt(t1.getText()); OP='%';
t1.setText("");
}
if(str.equals("EQ"))
{
v2=Integer.parseInt(t1.getText());
if(OP=='+')
result=v1+v2; else
if(OP=='-')
result=v1-v2; else
if(OP=='*')
result=v1*v2; else
if(OP=='/')
result=v1/v2; else
if(OP=='%')
result=v1%v2;
t1.setText(""+result);
}
if(str.equals("clear"))
{
t1.setText("");
}
}
OUTPUT:
EXPERIMENT NO.-05
Writing program in XML for creation of DTD, which specifies set of rules.
<?xml version="1.0"?>
<!DOCTYPE student[
<!ELEMENT student (name,address,std,marks)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT std (#PCDATA)>
<!ELEMENT marks (#PCDATA)>
]>
<student>
<name>Harshit Jaiswal</name>
<address>Bareilly</address>
<marks>94</marks>
</student>
OUTPUT:
EXPERIMENT NO.-06
Program to illustrate JDBC connectivity and maintaining database by sending
queries.
import java.sql.*;
import java.util.;
class Main
{
public static void main(String a[])
{
Statement st = con.createStatement();
int m = st.executeUpdate(sql);
if (m == 1)
System.out.println("inserted successfully : "+sql);
else
System.out.println("insertion failed");
con.close();
}
catch(Exception ex)
{
System.err.println(ex);
}
}}
OUTPUT:
EXPERIMENT NO.-07
Install APACHE TOMCAT web server. Access the static web pages for login id,
using this server.
<body>
<h2 align="center">Sign in</h2>
<form method="get" action="http://localhost:8888/india/Login.jsp">
<h3>
Enter ID <input type="text" name="t1"> <br>
Enter Password <input type="password" name="t2"> <br>
<input type="submit" value="Sign in">
</h3>
</body>
In the action attribute Login.jsp file is given to invoke. Assume localhost is the server. The port
number on which Tomcat is running is 8888. india is the folder created in Tomcat. The attribute
method can be given two values of either get or post; here, get is given.
Following is the server-side JSP file that includes a Scriptlet to understand what and how to code
Scriptlet.
%>
</body>
OUTPUT:
}catch(Exception e){System.out.println(e);}
}
}
SecondServlet.jav
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SecondServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response){ try{
response.setContentType("text/html"); PrintWriter
out = response.getWriter();
Cookie ck[]=request.getCookies();
out.print("Hello "+ck[0].getValue());
out.close();
}catch(Exception e){System.out.println(e);}
}
}
web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
EXPERIMENT NO.-09
Write a java program/servlet/JSP to connect database and extract data from the
tables and display them
Retrieve.jsp
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%
String id = request.getParameter("userid"); String
driver = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/"; String
database = "test";
String userid = "root"; String
password = ""; try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null; Statement
statement = null; ResultSet resultSet = null;
%>
<!DOCTYPE html>
<html>
<body>
<h1>Retrieve data from database in jsp</h1>
<table border="1">
<tr>
<td>first name</td><td>last name</td>
<td>City name</td>
<td>Email</td>
</tr>
<%
try{
connection = DriverManager.getConnection(connectionUrl+database, userid, password);
statement=connection.createStatement();
String sql ="select * from users"; resultSet
=statement.executeQuery(sql);
while(resultSet.next()){
%>
<tr>
<td><%=resultSet.getString("first_name") %></td>
<td><%=resultSet.getString("last_name") %></td>
<td><%=resultSet.getString("city_name") %></td>
<td><%=resultSet.getString("email") %></td>
</tr>
<%
connection.close();
} catch (Exception e) { e.printStackTrace();
}
%>
</table>
</body>
</html>
After retrieve the data from the data base the table look like this.
1. First Name
2. Last Name
3. Username
4. Password
5. Address
6. Contact Number
7. After filling all these details we have submit button, on click of that button
all the details will be stored.
Register_1.jsp
<tr>
<td>Last Name</td>
</tr> <td><input type="text" name="last_name" /></td>
<tr>
<td>UserName</td>
<td><input type="text" name="username" /></td>
</
tr>
<tr>
<td>Password</td>
</tr>
<tr>
<td>Address</td>
</tr> <td><input type="text" name="address" /></td>
<tr>
<td>Contact No</td>
<td><input type="text" name="contact" /></td>
</tr></table>
<input type="submit" value="Submit" /></form>
</body>
</html>
Code Line 37: Here we are taking a button of type submit and value is also submit. On
click of this button the action will go to corresponding guru_register servlet where all the
parameter values will be passed in the request.
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;
/**
RequestDispatcher req =
request.getRequestDispatcher("register_1.jsp");
req.include(request, response);
}
else
{
Explanation of code:
Code Line 14: Here we defining guru_servlet which is extending HttpServlet.
Code Line 18: This action doPost() method which will be called when we mention POST
in action attribute in the above JSP form.
Code Line 20-25:Here we are fetching the values from request i.efirst_name, last_name ,
username, password, address and contact using request.getParameter.
Code Line 27-32: Here we are taking if condition where we check any of the parameters
which are fetched from request as whether they are empty or not. If any of the parameter
is empty then it will enter this condition ( first_name.isEmpty() || last_name.isEmpty ||
username.isEmpty || password.isEmpty || address.isEmpty || contact.isEmpty()) and we
have to fetch RequestDispatcher object using request object which will forward request to
register_1.jsp. Here we are also including request and response objects.
Code Line 33-37: This case will execute when any of the parameter is not empty .We
will have to fetch requestDispatcher object using request object which will forward
request to register_2.jsp.Here we are forwarding request and response objects.
Register_2.jsp
When we click on register_1.jsp, we will get a form which will have details like first
name, last name, username, password, address, contact. All the details have been filled.
When we click on submit button then we get the message as "Welcome User"
EXPERIMENT NO.-11
Design and implement a simple shopping cart example with session
tracking API.
import
java.io.*;
import
javax.servlet.*;
import javax.servlet.http.*;
res.setContentType("text/
html"); PrintWriter out =
res.getWriter();
out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
out.println("<BODY><H1>Session Tracking Demo</H1>");
out.println("</BODY></HTML>");
}
OUTPUT:
SessionTracker
Session Tracking Demo
currently have the following items in your cart:
APPLE
BANANA
MANGO
Would you like to Add More Items
Check Out