[go: up one dir, main page]

0% found this document useful (0 votes)
26 views41 pages

Web Technoly Lab Krishna Kumar

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

Web Technoly Lab Krishna Kumar

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

Meerut Institute of Technology, Meerut

Department of Computer Science & Engineering


(Affiliated to DR. A.P.J KALAM TECHNICAL UNIVERSITY LUCKNOW)

PRACTICAL FILE
COMPUTER SCIENCE AND ENGINEERING

WEB TECHNOLOGY LAB


(KCS-652)
B.Tech. VI SEMESTER

Under the Supervision: Name of Student: Lakshay Panwar


Mr. Kishan Raj
(Assistant Professor) Roll Number: 2102920100053

Session (2023-2024)
INDEX
S.No. Name of the Date Page No. Signature of
Experiment Concerned Faculty
1 Write HTML/Java
scripts to display your
CV in navigator, your
Institute website,
Department Website and
Tutorial website for
specific subjects.

2 Write an HTML
program to design an
entry form of student
details and send it to a
database server like
SQL, Oracle or MS
Access.

3 Write programs using


Javascript for Web Page
to display browsers
information.
4 Write a Java applet to
display the Application
Program screen i.e.
calculator and other.

5 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.

6 Program to illustrate
JDBC connectivity.
Program for maintaining
databases by sending
queries. Design and
implement a simple
servlet book query with
the help of JDBC &
SQL.
Create MS Access
Database, Create on
ODBC link, Compile &
execute JAVA JDBC
Socket.

7 Install TOMCAT web


server and APACHE.
Access the above
developed static web
pages for books website,
using these servers by
putting the web pages
developed.

8 Assume four users


user1, user2, user3 and
user4 having the
passwords pwd1, pwd2,
pwd3 and pwd4
respectively. Write a
servlet for doing the
following. Create a
Cookie and add these
four user id’s and
passwords to this
Cookie. 2. Read the user
id and passwords
entered in the Login
form and authenticate
with the values available
in the cookies.

9 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
10 submit button in the
registration page.

Write a JSP which


inserts 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
username and password
from the database
PROGRAM 1

Objective: Write HTML/Java scripts to display your CV in


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

Code:
<html>
<head>

<title></title>
</head>
<body>
<div id="header">
<p id="name"><h2>Deep Laxman Sukhwani</h2></p>
<h4><a href="mailto:deepsukhwani@gmail.com"></h4><p
id="email">E-Mail:deepsukhwani@gmail.com</p></a>
</div>
<div class="left">
</div>
<div class="right">
<h3>CV Highlights</h3>
<p>
<ul>
<li>Currently going through CS253 – Web Application Engineering and CS61A
– Structure & Interpretation of Computer Programs</li>
<li>Learnt basic Python, JavaScript, HTML, CSS on Codecademy.com.</li> <li>An
independent, dedicated, efficient person. These attributes are proved through
the series of courses I have taken or I am taking as of now independently through
online platforms.</li>
<li>Good Communication Skills, Presentation Skills, attitude towards leadership,
authorisation and delegation, conflict resolution and negotiation and a very good team
worker.</li></ul>
</p>
<h3>Professional Experience</h3>
<h4 id="company-name">Wingify Software Pvt Ltd</h4>
<p id="job-title"><strong>Support Engineer (Technical
Support)</strong></p> <p id="job-responsibilities">Job Responsbilities</p>
<p>
<ul>
<li>Answer customer queries over email / ticketing system</li>
<li>Interact with our engineering team to get software issues and bugs resolved</li>
<li>Occasionally interact with customers over Skype or telephone</li> <li>Contribute
ideas to the team on how customers can be delighted</li></ul>
</p>
<h3>Educational Qualifications</h3>
<table border=2>
<tr id="heading">
<td>Qualification</td>
<td>University</td>
<td>Percentage / Grades</td>
<td>Year</td>
</tr>
<tr>
<td>S.S.C</td>
<td>Delhi</td>
<td>75.57%</td>
<td>2004</td>
</tr>
<tr>
<td>H.S.C (Mathematics Stream)</td>
<td>Delhi</td>
<td>72.40%</td>
<td>2006</td>
</tr>
<tr>
<td>Graduation</td>
<td>MIET Meerut</td>
<td>A Grade</td>
<td>2010</td>
</tr>

</table>
<h3>Independent Courses</h3>
<p>
<ul>
<li>
<span id="course-name">HTML & CSS for Beginners – Web Fundamentals</span>
</li>
<li>
<span id="course-name">Python – Fundamentals and Data Structure </span>
</li> <li>
<span id="course-name">JavaScript – Programming Basics, JS Apps and Build
Games </span> </li>
<li>

</ul>
<h3>Technical Skills</h3>
<p>
<ul>
<li>
<span id="course-name">Operating Systems:</span> DOS, Windows 8, Windows
10</li>
<li>
<span id="course-name">Application Software:</span> Office 97-2003; Office
XP, Office 2007</li>
<li>
<span id="course-name">Programming Skills:</span>HTML, CSS, Python,
JavaScript, learning C and C++</li></ul>
</p>
<h3>Certifications / Awards:</h3>
<p>
<ul>
<li>AWS Cloud Practitioner Certification in 2008</li>
<li>AWS Solutions Architect Certification in 2009</li>
</ul>
</p>
<h3>Personal Information:</h3>
<p><ul>
<li>Date of Birth: 7/3/1994 </li>
<li>Father's Name: Mr. Rohit Kumar </li>
<li>Category:OBC </li>
<li> Nationality: Indian</li>
<li>Permanent Address:Delhi Road, Meerut U.P.</li>
<li>Communication Address:Delhi Road, Meerut U.P</li>
<li>Mobile No.:123456789 </li>
<li> Email id:abc@gmail.com</li>
<li>
<span id="course-name">Languages Known:</span>English, Hindi, Gujarati and
Sindhi</li>
</p>
<ul>

<h2>Hobbies</h2>
I love reading Finance and IT related books / magazines, playing Chess, swimming,
listening music, surfing Internet, self-learning through e-courses.
</p>
<h3>Other Information</h3>
<p>
<ul>
<li>
<span id="course-name">Expected Salary:</span>As per company standards</li>
<li>
<span id="course-name">Area of Interest:</span>Software Development,
Programming, Start-ups, Coding, App Development, Technical Support, Support
Engineer, Customer Happiness, Client service, </li>
<li>
<span id="course-name">Joining Date:</span>Immediate</li></ul>
</p>
<h3>Declaration</h3>
<p>
I hereby declare that the details furnished above are true and correct to the best of my
knowledge and belief.</p>
</div>
<div id="footer"></div>
</body>
</html>
Output:
Deep Laxman Sukhwani
E-Mail:deepsukhwani@gmail.com
CV Highlights

● Currently going through CS253 – Web Application Engineering and CS61A


– Structure & Interpretation of Computer Programs
● Learnt basic Python, JavaScript, HTML, CSS on Codecademy.com.
● An independent, dedicated, efficient person. These attributes are proved through
the series of courses I have taken or I am taking as of now independently through
online platforms.
● Good Communication Skills, Presentation Skills, attitude towards leadership,
authorisation and delegation, conflict resolution and negotiation and a very
good team worker.

Professional Experience

Wingify Software Pvt Ltd


Support Engineer (Technical Support)
Job Responsbilities

● Answer customer queries over email / ticketing system


● Interact with our engineering team to get software issues and bugs resolved
● Occasionally interact with customers over Skype or telephone
● Contribute ideas to the team on how customers can be delighted
Educational Qualifications
Qualification University Percentage / Grades Year
S.S.C Delhi 75.57% 2004
H.S.C (Mathematics Stream) Delhi 72.40% 2006
Graduation MIET Meerut A Grade 2010
Independent Courses

● HTML & CSS for Beginners – Web Fundamentals


● Python – Fundamentals and Data Structure
● JavaScript – Programming Basics, JS Apps and Build Games
Technical Skills

● Operating Systems: DOS, Windows 8, Windows 10


● Application Software: Office 97-2003; Office XP, Office 2007
● Programming Skills:HTML, CSS, Python, JavaScript, learning C and C++
Certifications / Awards:

● AWS Cloud Practitioner Certification in 2008


● AWS Solutions Architect Certification in 2009
Personal Information:

● Date of Birth: 7/3/1994


● Father's Name: Mr. Rohit Kumar
● Category:OBC
● Nationality: Indian
● Permanent Address:Delhi Road, Meerut U.P.
● Communication Address:Delhi Road, Meerut U.P
● Mobile No.:123456789
● Email id:abc@gmail.com
● Languages Known:English, Hindi, Gujarati and Sindhi
Hobbies
I love reading Finance and IT related books / magazines, playing
Chess, swimming, listening music, surfing Internet, self-learning
through e-courses.
Other Information

▪ Expected Salary:As per company standards

▪ Area of Interest:Software Development, Programming, Start-ups,


Coding, App Development, Technical Support, Support Engineer,
Customer Happiness, Client service,

▪ Joining Date:Immediate
Declaration
I hereby declare that the details furnished above are true and correct to
the best of my knowledge and belief.
PROGRAM-2

Objective: Write an HTML program to design an entry form of


student details and send it to store at database server like SQL,
Oracle or MS Access.

Code:
<html>
<head>
<script type="text/javascript" src="validate.js" ></script>
</head>
<body bgcolor="aqua" bolder="5">
<form action="register.jsp" name="StudentRegistration" method=”post”>
<table cellpadding="2" width="50%" border="10" align="center"cellspacing="2">
<tr>
<td colspan=2>
<center><font size=4><b>Student Registration Form</b></font></center>
</td>
</tr>
<tr>
<td>Name</td>
<td><input type=text name=textnames id="textname" size="30"></td>
</tr>
<tr>
<td>Father Name</td>
<td><input type="text" name="fathername" id="fathername" size="30"></td>
</tr>
<tr>
<td>Postal Address</td>
<td><input type="text" name="paddress" id="paddress" size="30"></td>
</tr>
<tr>

<td>Personal Address</td>
<td><input type="text" name="personaladdress" id="personaladdress" size="30"></td>
</tr>
<tr>
<td>Sex</td>
<td><input type="radio" name="sex" value="male" size="10">Male
<input type="radio" name="sex" value="Female" size="10">Female</td>
</tr>
<tr>
<td>City</td>
<td><select name="City">
<option value="-1" selected>select..</option>
<option value="New Delhi">NEW DELHI</option>
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Patna">PATNA</option>
</select></td>
</tr>
<tr>
<td>Course</td>
<td><select name="Course">
<option value="-1" selected>select..</option>
<option value="B.Tech">B.TECH</option>
<option value="MCA">MCA</option>
<option value="MBA">MBA</option>
<option value="BCA">BCA</option>
</select></td>
</tr>
<tr>
<td>District</td>
<td><select name="District">
<option value="-1" selected>select..</option>
<option value="Nalanda">NALANDA</option>
<option value="UP">UP</option>
<option value="Goa">GOA</option>
<option value="Patna">PATNA</option>
</select></td>
</tr>
<tr>

<td>State</td>
<td><select Name="State">
<option value="-1" selected>select..</option>
<option value="New Delhi">NEW DELHI</option>
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Bihar">BIHAR</option>
</select></td>
</tr>
<tr>
<td>PinCode</td>
<td><input type="text" name="pincode" id="pincode" size="30"></td>
</tr>
<tr>
<td>EmailId</td>
<td><input type="text" name="emailid" id="emailid" size="30"></td>
</tr>
<tr>
<td>DOB</td>
<td><input type="text" name="dob" id="dob" size="30"></td>
</tr>
<tr>
<td>MobileNo</td>
<td><input type="text" name="mobileno" id="mobileno" size="30"></td>
</tr>
<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form" /></td>
</tr>
</table>
</form><br><br>
<h1><a href="MainPage.html">Back</a></h1>
</body>
</html>
Output
PROGRAM 3

Objective: Write programs using Java script for Web Page


to display browsers information.

Code:

<html xmlns="http://www.w3.org/1999/xhtml"
> <head runat="server">
<title>Browser Information</title>

<script language=javascript>
function show()
{

document.write("Name "+navigator.appName+"<br>");
document.write("Version "+navigator.appVersion +"<br>");
document.write("Codename " +navigator.appCodeName
+"<br>"); document.write("Cookie
enable"+navigator.cookieEnabled +"<br>");
document.write("Java Enable"+navigator.javaEnabled
+"<br>"); document.write("Mime
type"+navigator.mimeTypes +"<br>");
document.write("Platform"+navigator.platform +"<br>");
document.write("Plug ins"+navigator.plugins +"<br>");
document.write("System
Language"+navigator.systemLanguage +"<br>");
document.write("User language"+navigator.userAgent
+"<br>"); document.write("User
Agent"+navigator.userAgent +"<br>");

</script>
</head>
<body>
<form id="form1">
<div>
<input id="Button1" type="button" value="Click me" onclick="show()" />

</div>
</form>
</body>
</html>
OUTPUT :
PROGRAM 4

Objective: Write a Java applet to display the Application Program screen i.e.
calculator and other.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

/*
<applet code="Cal" width=300 height=300>
</applet>
*/

public class Cal extends Applet


implements ActionListener
{
String msg=" ";
int v1,v2,result;
TextField t1;
Button b[]=new Button[10];
Button add,sub,mul,div,clear,mod,EQ;
char OP;
public void init()
{
Color k=new Color(120,89,90);
setBackground(k);
t1=new TextField(10);
GridLayout gl=new GridLayout(4,5);
setLayout(gl);
for(int i=0;i<10;i++)
{
b[i]=new Button(""+i);
}
add=new Button("add");
sub=new Button("sub");
mul=new Button("mul");
div=new Button("div");
mod=new Button("mod");
clear=new Button("clear");
EQ=new Button("EQ");
t1.addActionListener(this);
add(t1);
for(int i=0;i<10;i++)
{
add(b[i]);
}
add(add);
add(sub);
add(mul);
add(div);
add(mod);
add(clear);
add(EQ);
for(int i=0;i<10;i++)
{
b[i].addActionListener(this);
}
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
EQ.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)


{
String str=ae.getActionCommand();
char ch=str.charAt(0);
if ( Character.isDigit(ch))
t1.setText(t1.getText()+str);
else
if(str.equals("add"))
{
v1=Integer.parseInt(t1.getText());
OP='+';
t1.setText("");
}
else if(str.equals("sub"))
{
v1=Integer.parseInt(t1.getText());
OP='-';
t1.setText("");
}
else if(str.equals("mul"))
{
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
PROGRAM 5

Objective: 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.

XML document with an internal DTD


<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note
(to,from,heading,body)> <!ELEMENT to
(#PCDATA)> <!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this
weekend</body> </note>

XML document with a reference to an external DTD


<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this
weekend!</body> </note>

And here is the file "note.dtd", which contains the DTD:

<!ELEMENT note
(to,from,heading,body)> <!ELEMENT to
(#PCDATA)> <!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>

Code:

1.XML :

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


<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>

XSL:
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Output:
In Internet Explorer

Title Artist
Empire
Bob Dylan
Burlesque
Hide your heart Bonnie Tyler
PROGRAM 6

Objective: Program to illustrate JDBC connectivity. Program for maintaining database by


sending queries. Design and implement a simple servlet book query with the help of JDBC
& SQL. Create MS Access Database, create on ODBC link, Compile & execute
JAVA JDVC Socket.

Theory:

Creating JDBC Application


There are following six steps involved in building a JDBC application −
● Import the packages: Requires that you include the packages containing
the JDBC classes needed for database programming. Most often, using
import java.sql.* will suffice.
● Register the JDBC driver: Requires that you initialize a driver so you can open a
communication channel with the database.
● Open a connection: Requires using the DriverManager.getConnection() method to
create a Connection object, which represents a physical connection with the database.
● Execute a query: Requires using an object of type Statement for building and
submitting an SQL statement to the database.
● Extract data from result set: Requires that you use the appropriate
ResultSet.getXXX() method to retrieve the data from the result set.
● Clean up the environment: Requires explicitly closing all database resources
versus relying on the JVM's garbage collection.
CODE:

//STEP 1. Import required


packages import java.sql.*;

public class FirstExample {


// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/EMP";
// Database credentials
static final String USER = "username";
static final String PASS = "password";

public static void main(String[] args) {


Connection conn = null;
Statement stmt = null;
try{
//STEP 2: Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");

//STEP 3: Open a connection


System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,USER,PASS);

//STEP 4: Execute a query


System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT id, first, last, age FROM
Employees"; ResultSet rs = stmt.executeQuery(sql);

//STEP 5: Extract data from result set


while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");

//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
//STEP 6: Clean-up
environment rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing we can do
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}//end FirstExample

Servlet And JDBC


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class JDBCServlet extends HttpServlet {
public void doGet(HttpServletRequest
inRequest,
HttpServletResponse outResponse) throws ServletException,
IOException {

PrintWriter out = null;


Connection connection = null;
Statement statement;
ResultSet rs;

try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager
.getConnection("jdbc:mysql://localhost/products");
statement = connection.createStatement();

outResponse.setContentType("test/html");
out = outResponse.getWriter();

rs = statement.executeQuery("SELECT ID, title, price FROM product");

out.println("<HTML><HEAD><TITLE>Products</TITLE></HEAD>");
out.println("<BODY>");
out.println("<UL>");

while (rs.next()) {
out.println("<LI>" + rs.getString("ID") + " "
+ rs.getString("title") + " " + rs.getString("price"));
}

out.println("</UL>");
out.println("</BODY></HTML>");
} catch (ClassNotFoundException e)
{ out.println("Driver Error");
} catch (SQLException e) {
out.println("SQLException: " +
e.getMessage());
}
}
public void doPost(HttpServletRequest inRequest,
HttpServletResponse outResponse) throws ServletException,
IOException {
doGet(inRequest, outResponse);
}
}
PROGRAM 7

Objective: Install TOMCAT web server and APACHE. Access the above
developed static web pages for books web site, using these servers by putting the
web pages developed .

Theory:

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:

<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>
PROGRAM 8

Objective: Assume four users user1, user2, user3 and user4 having the
passwords pwd1, pwd2, pwd3 and pwd4 respectively. Write a servlet for
doing the following.
1. Create a Cookie and add these four user id’s and passwords to this Cookie.
2. Read the user id and passwords entered in the Login form (week1) and
authenticate with the values (user id and passwords) available in the cookies.

PROGRAM:
cologin.html:
<html>
<head>
<title> login Page </title>
<p style= "background:yellow; top:100px; left:250px; position:absolute; ">
</head>
<body>
<form ACTION="clogin">
<label> Login </label>
<input type="text" name="usr" size="20"> <br> <br>
<label> Password </label>
<input type="password" name="pwd" size="20"> <br> <br>
<input type="submit" value="submit">
</form>
</body>
</html>
cologin1.html
<html>
<head>
<title> login Page </title>
<p style= "background:yellow; top:100px; left:250px; position:absolute; ">
</head>
<body>
<form ACTION="clogin1">
<label> Login </label>
<input type="text" name="usr" size="20"> <br> <br>
<label> Password </label>
<input type="password" name="pwd" size="20"> <br> <br>
<input type="submit" value="submit">
</form>
</body>
</html>

Addcook.java:
import javax.servlet.* ;
import javax.servlet.http.*;
import java.io.*;
public class Addcook extends HttpServlet
{
String user,pas;
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
Cookie c1=new Cookie("usr1","suni");
Cookie p1=new Cookie("pwd1","ani");
Cookie c2=new Cookie("usr2","abc");
Cookie p2=new Cookie("pwd2","123");
Cookie c3=new Cookie("usr3","def");
Cookie p3=new Cookie("pwd3","456");
Cookie c4=new Cookie("usr4","mno");
Cookie p4=new Cookie("pwd4","789");
res.addCookie(c1);
res.addCookie(p1);
res.addCookie(c2);
res.addCookie(p2);
res.addCookie(c3);
res.addCookie(p3);
res.addCookie(c4);
res.addCookie(p4);
out.println("COOKIE ADDED");
}
}
Clogin.java:
import javax.servlet.* ;
import javax.servlet.http.*;
import java.io.*;
public class Clogin extends HttpServlet
{
String user,pas;
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
user=req.getParameter("usr");
pas=req.getParameter("pwd");
Cookie[] c=req.getCookies();
for(int i=0;i<c.length;i++)
{
if((c[i].getName().equals("usr1")&&c[i+1].getName().equals("pwd1"))|| c[i].getName().equals("usr2")
&&c[i+1].getName().equals("pwd2"))||(c[i].getName().equals("usr3")&&
c[i+1].getName().equals("pwd3"))||(c[i].getName().equals("usr4")&& c[i+1].getName().equals("pwd4") ))
{
if((user.equals(c[i].getValue()) && pas.equals(c[i+1].getValue())) )
{
//RequestDispatcher rd=req.getRequestDispatcher("/cart.html");
rd.forward(req,res);
}
else
{
out.println("YOU ARE NOT AUTHORISED USER ");
//res.sendRedirect("/cookdemo/cologin.html");
}
}
}
}
}

Web.xml:
<web-app>
<servlet>
<servlet-name>him</servlet-name>
<servlet-class>Clogin</servlet-class>
</servlet>
<servlet>
<servlet-name>him1</servlet-name>
<servlet-class>Addcook</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>him</servlet-name>
<url-pattern>/clogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>him1</servlet-name>
<url-pattern>/clogin1</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
2. Read the user id and passwords entered in the Login form (week1) and authenticate with the values (user
id and passwords) available in the cookies.
If he is a valid user (i.e., user-name and password match) you should welcome him by name (user-name) else
you should display “You are not an authenticated user “.
Use init-parameters to do this. Store the user-names and passwords in the webinf.xml and access them in
the servlet by using the getInitParameters() method.
home.html:
<html>
<head>
<title>Authentication</title>
</head>
<body>
<form action="ex1">
<label>Username </label>
<input type="text"size="20" name="user"><br><br>
password<input type="text" size="20" name="pwd"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
Example1.java
import javax.servlet.*;
import java.io.*;
public class Example1 extends GenericServlet
{
private String user1,pwd1,user2,pwd2,user3,pwd3,user4,pwd4,user5,pwd5;
public void init(ServletConfig sc)
{
user1=sc.getInitParameter("username1");
pwd1=sc.getInitParameter("password1");

user2=sc.getInitParameter("username2");
pwd2=sc.getInitParameter("password2");

user3=sc.getInitParameter("username3");
pwd3=sc.getInitParameter("password3");

user4=sc.getInitParameter("username4");
pwd4=sc.getInitParameter("password4");
}
Public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
user5=req.getParameter("user");
pwd5=req.getParameter("pwd");
if((user5.equals(user1)&&pwd5.equals(pwd1))||(user5.equals(user2)&&pwd5.equals(pwd2))||(user5.equals(user3)&&pwd5.equals(
pwd3))||(user5.equals(user4)&&pwd5.equals(pwd4)))
out.println("<p> welcome to"+user5.toUpperCase());
else
out.println("You are not authorized user");
}
}

web.xml:
<web-app>
<servlet>
<servlet-name>Example</servlet-name>
<servlet-class>Example1</servlet-class>
<init-param>
<param-name>username1</param-name>
<param-value>pvpsit</param-value>
</init-param>
<init-param>
<param-name>password1</param-name>
<param-value>cse</param-value>
</init-param>
<init-param>
<param-name>username2</param-name>
<param-value>1234</param-value>
</init-param>
<init-param>
<param-name>password2</param-name>
<param-value>4567</param-value>
</init-param>
<init-param>
<param-name>username3</param-name>
<param-value>cse</param-value>
</init-param>
<init-param>
<param-name>password3</param-name>
<param-value>pvpsit</param-value>
</init-param>
<init-param>
<param-name>username4</param-name>
<param-value>wt</param-value>
</init-param>
<init-param>
<param-name>password4</param-name>
<param-value>lab</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Example</servlet-name>
<url-pattern>/ex1</url-pattern>
</servlet-mapping>
</web-app>
PROGRAM 9

Objective: 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.

PROGRAM:
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>

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
{
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>
OUTPUT:
PROGRAM 10:

Objective: Write a JSP which insert the details of the 3 or 4 users who register with the
the web site by using registration form. Authenticate the user when he submits the login
form using the username and password.
PROGRAM:
Login.html:
<!--Home.html-->
<html> <body>
<center><h1>XYZ Company Ltd.</h1></center>
<table border="1" width="100%" height="100%">
<tr>
<td valign="top" align="center"><br/>
<form action="auth.jsp"><table>
<tr>
<td colspan="2" align="center"><b>Login Page</b></td>
</tr>
<tr>
<td colspan="2" align="center"><b>&nbsp;</td>
</tr>
<tr>
<td>User Name</td>
<td><input type="text" name="user"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pwd"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="LogIN"/></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Auth.jsp:
<%@page import="java.sql.*;"%>
<html>
<head>
<title>
This is simple data base example in JSP</title>
</title>
</head>
<body bgcolor="yellow">
<%!String uname,pwd;%>
<%
uname=request.getParameter("user");
pwd=request.getParameter("pwd");
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@195.100.101.158:1521:CCLAB","scott","tiger");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select name,password from personal where name='"+uname+"' and
password='"+pwd+"'"); if(rs.next())
{
out.println("Authorized person");
}
else
{
out.println("UnAuthorized person");
}
con.close();
}
catch(Exception e){out.println(""+e);}
%>
</body>
</html>

OUTPUT:

You might also like