0% found this document useful (0 votes)
31 views42 pages

WT Record

Here are the steps to convert static web pages to dynamic using Servlets and cookies in Tomcat: 1. Install Apache Tomcat on your system by downloading and running the installer. 2. Create a directory (e.g. myapp) under Tomcat's webapps folder to hold your application files. 3. Under myapp, create a WEB-INF folder and place your static HTML files outside of it. 4. Create Servlet classes that extend HttpServlet to handle requests and place them under WEB-INF/classes. 5. Add servlet mappings in WEB-INF/web.xml that map requests to the Servlet classes. 6. Modify the static HTML pages
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)
31 views42 pages

WT Record

Here are the steps to convert static web pages to dynamic using Servlets and cookies in Tomcat: 1. Install Apache Tomcat on your system by downloading and running the installer. 2. Create a directory (e.g. myapp) under Tomcat's webapps folder to hold your application files. 3. Under myapp, create a WEB-INF folder and place your static HTML files outside of it. 4. Create Servlet classes that extend HttpServlet to handle requests and place them under WEB-INF/classes. 5. Add servlet mappings in WEB-INF/web.xml that map requests to the Servlet classes. 6. Modify the static HTML pages
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/ 42

EX. NO.

1 IMAGE MAPPING IN HTML

AIM:

To create a web page which includes a map and display the related information
when a hot spot is clicked in the map.

PROCEDURE:

1. Create a html file with map tag.


2. Set the source attribute of the img tag to the location of the image and also set the
use map attribute.
3. Specify an area with name, shape and href set to the appropriate values.
4. Repeat step 3 as many hot spots you want to put in the map.
5. Create html files for each and every hot spot the user will select.

PROGRAM:

ImageMap.html
<HTML>
<HEAD>
<TITLE>Image Map</TITLE></HEAD>
<BODY>
<img src="./india_map.jpeg" usemap="#metroid" ismap="ismap" >
<map name="metroid" id="metroid">
<area href="TamilNadu.html" shape="rect" coords = "64,87,247,531" title ="TamilNadu"/>
<area href="Karnataka.html" shape="rect" coords = "130,531,164,535" title ="Karnataka" />
<area href="AndhraPradesh.html" shape="rect" coords = "227,511,198,503" title ="Andhra
Pradesh" />
<area href="Kerala.html" shape="rect" coords = "154,606,166,621" title ="Kerala" />
<area href="Maharashtra.html" shape="rect" coords = "64,87,247,531" title ="Maharashtra" />
<area href="WestBengal.html" shape="rect" coords = "98,36,62,429" title ="West Bengal"
/></map>
</BODY>
</HTML>

Tamilnadu.html
<HTML>
<HEAD>
<TITLE>About Tamil Nadu</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Tamil Nadu</H1>
</CENTER><HR>
<UL>
<LI>Area : 1,30,058 Sq. Kms.</LI>
<LI>Capital : Chennai</LI>
<LI>Language : Tamil</LI>
<LI>Population : 6,21,10,839</LI>
</UL>
<hr>
<a href='./ImageMap.html'>India Map</a>
</BODY>
</HTML>

AndhraPradesh.html
<HTML>
<HEAD>
<TITLE>About Andhra Pradesh</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Andhra Pradesh</H1>
</CENTER>
<HR>
<UL>
<LI>Area : 2,75,068 Sq. Kms</LI>
<LI>Capital : Vishakhapatnam</LI>
<LI>Language : Telugu</LI>
<LI>Population : 7,57,27,541</LI>
</UL>
<hr>
<a href='./ImageMap.html'>India Map</a>
</BODY>
</HTML>

Karnataka.html
<HTML>
<HEAD>
<TITLE>About Karnataka</TITLE>
</HEAD>
<BODY>
<CENTER><H1>Karnataka</H1>
</CENTER><HR>
<UL>
<LI>Area : 1,91,791 Sq. Kms</LI>
<LI>Capital : Bengaluru</LI>
<LI>Language : Kannada</LI>
<LI>Population : 5,27,33,958</LI>
</UL>
<hr>
<a href='./ImageMap.html'>India Map</a>
</BODY>
</HTML>
Kerala.html
<HTML>
<HEAD>
<TITLE>About Kerala</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>Kerala</H1></CENTER>
<HR>
<UL>
<LI>Area : 38,863 Sq. Kms.</LI>
<LI>Capital : Thiruvananthapuram</LI>
<LI>Language : Malayalam</LI>
<LI>Population : 3,18,38,619</LI>
</UL>
<hr>
<a href='./ImageMap.html'>India Map</a>
</BODY>
</HTML>

Maharashtra.html
<HTML>
<HEAD>
<TITLE>About Maharashtra</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>Maharashtra</H1></CENTER>
<HR>
<UL>
<LI>Area : 3,07,713 Sq. Kms.</LI>
<LI>Capital : Mumbai</LI>
<LI>Language : Marathi</LI>
<LI>Population : 11,23,74,333</LI>
</UL>
<hr>
<a href='./ImageMap.html'>India Map</a>
</BODY>
</HTML>

WestBengal.html
<HTML>
<HEAD>
<TITLE>About West Bengal</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1>West Bengal</H1></CENTER>
<HR>
<UL>
<LI>Area : 88,752 Sq. Kms.</LI>
<LI>Capital : Kolkata</LI>
<LI>Language : Bengali</LI>
<LI>Population : 9,13,47,736</LI>
</UL>
<hr>
<a href='C:\Users\msren\Desktop\ImageMap.html'>India Map</a>
</BODY>
</HTML>
OUTPUT:
ImageMap.html

Tamilnadu.html
Andhrapradesh.html

Karnataka.html
Kerala.html

Maharashtra.html
WestBengal.html

RESULT:
Thus the creation of a webpage which includes a map and display the related information when
a hot spot is clicked in the map was executed successfully.
EX. NO. 2 CASCADING STYLE SHEETS

AIM:
To create a web page that displays college information using various style sheet.

PROCEDURE:
1.Create a web page with frame sets consisting two frames.
2.In the first frame include the links.
3.In the second frame set display the web page of the link.
4.Create a external style sheets.
5.Create a embedded style sheets
6.Create a inline and internal style sheets and make it link to the external style sheets
PROGRAM:
xyz.css
h3
{
font-family:arial; font-size:20; color:cyan
}
table{
border-color:green
}
td
{
font-size:20pt; color:magenta
}

aalimec.html
<html>
<head>
<h1>
<center>ALL STYLE SHEETS</center>
</h1>
<title>USE of INTERNAL and EXTERNAL STYLE SHEETS </title>
<link rel="stylesheet" href="xyz.css" type="text/css">
<style type="text/css">
.vid
{
font-family:verdana;
font-style:italic;
color:red;
text-align:center
}
.ani
{
font-family:tahoma;
font-style:italic;
font-size:20;
text-align:center;
}
font
{
font-family:georgia;
color:blue;
font-size:20;
}
ul
{
list-style-type:circle
}
p{
font-family: georgia, serif;
font-size: x-small;
}
hr
{
color: #ff9900; height: 1px
}
a:hover
{
color: #ff0000;
text-decoration: none
}
</style>
</head>
<body>
<h1 style="color:blue;margin-left:30px;">Welcome</h1> //In-line style Sheet
<ol style="list-style-type:lower-alpha">
<b>Aalim Muhammed Salegh College of Engineering </b>
<br>
<br>
<br>
<li> EEE</li>
<li> ECE </li>
<li> MECH</li>
<li> CSE</li>
</ol>
<p style="font-size:20pt;color:purple">Details</p>
<h2 class="vid"> Aalim Muhammed Salegh College of Engineering </h2><br>
<p class="ani"><br>It is approved by AICTE(All India Council for Technical Education). It is
affliated to Anna University. It is an NAAC certified Institution.<br></p>
<font><center> Nizara Educational Campus, Muthapudupet, Avadi-IAF, Chennai-600 055. </center>
</font>
<br>
<br>
<font>
<h2>List of Courses offered</h2>
<ul>
<li>Computer Science and Engineering</li>
<li>Electronics and Communication Engineering</li>
<li>Mechanical Engineering</li>
<li>Electrical and Electronics Engineering</li>
</ul>
</font>
<h3>Results of CSE students</h3>
<table width="100%" cellspacing="2" cellpadding="2" border="5"><tr>
<th>STUDENT NAME</th><th>MARKS</th><th>RESULT</th>
</tr>
<tr>
<td align="center">A</td><td align="center">100</td>
<td align="center">PASS</td>
</tr>
<tr>
<td align="center">B</td><td align="center">99</td>
<td align="center">PASS</td>
</tr>
<tr>
<td align="center">C</td><td align="center">98</td>
<td align="center">PASS</td></tr>
</table>
</body>
</html>
OUTPUT:

aalimec.html

Result:
Thus the creation of a web page that displays college information using various style sheet was
successfully executed and verified.
EX.No.3 VALIDATING THE INFORMATION USING DHTML

AIM:
To validate the information using DHTML

PROGRAM:

<!DOCTYPE html>
<html>
<head>
<title>Form Validation using DHTML</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-image: url("pic1.webp");
background-size: cover;
background-repeat: no-repeat;
}
.error {
color: black;
}
.input-container {
padding: 10px;
}
form {
text-align: left;
background-color: #ffd4e8 ;
padding: 50px;
border-radius: 15px;
box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.3);
}
.success {
color: green;
text-align: center;
margin-top: 20px;
font-size: 1.2em;
text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
}
input[type="submit"] {
background-color: #f257a0;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
input[type="submit"]:hover {
background-color: #45a049;
}

h2 {
font-family: "Courier New", cursive, sans-serif;
color: black;
}
</style>
<script>
function showErrorPopup(message) {

alert(message);
}
function validateForm(event) {
event.preventDefault();

var name = document.forms["myForm"]["name"].value;


var email = document.forms["myForm"]["email"].value;
var password = document.forms["myForm"]["password"].value;
if (name == "" && email == "" && password == "") {
showErrorPopup("This page says: All fields need to be filled.");
return;}
if (name == "") {
showErrorPopup("This page says: The name field needs to be filled.");
return; // Stop further processing
}

if (email == "") {
showErrorPopup("This page says: The email field needs to be filled.");
return; // Stop further processing
}

if (password == "") {
showErrorPopup("This page says: The password field needs to be filled.");
return; // Stop further processing
}

// If all fields are filled, show success message


document.getElementById("successMessage").innerHTML = "Submitted Successfully!";
}
</script>
</head>
<body>
<h2>Form Validation using DHTML</h2>
<div class="error" id="errorMessages"></div>
<form name="myForm" onsubmit="validateForm(event)" method="post">
<div class="input-container">
<label for="name">Name:</label>
<input type="text" name="name">
</div>
<div class="input-container">
<label for="email">Email:</label>
<input type="email" name="email">
</div>
<div class="input-container">
<label for="password">Password:</label>
<input type="password" name="password">
</div>
<div>
<input type="submit" value="Submit">
</div>
</form>
<div class="success" id="successMessage"></div>
</body>
</html>
OUTPUT:

Result:
Thus the creation of a web page that displays validating web form controls using DHTML was
successfully executed and verified.
Ex.No.4 INSTALLATION OF APACHE TOMCAT WEB SERVER

AIM:

To install TOMCAT web server. Convert the static web pages of assignments 2 into dynamic web
pages using Servlets and cookies.

PROCEDURE:

1.First install the tomcat into the system.


2.Then make a subdirectly(eg., tr) in the \tomcat\webapps.
3.Under tr create WEB-INF directory and also place the html files in this tr directory only.
4.Next under WEB-INF create two subclasses lib,classes and web.xml Next place all the class files
under the classes and jar files(servlet-api.jar,classes12.jar etc…) under lib subdirectories.
5.After this start tomcat by giving the following command at the instll_dir>tomcat>bin Catalina.bat
run
6.At the I.E(web browser) give the url as http;//localhost:8080//tr/htmlfile or servlet url pattern Portno
8080 is assigned for the tomcat.

PROGRAM:
Main.html
<html>
<head>
<title> ONLINE BOOK STORES</title>
</head>
<body bgcolor="pink">
<marquee><h1 align=”center”><b><u><font color="white">ONLINE BOOK
STORAGE</u></font>
</b></h1></marquee>
<H2 ALIGN="CENTER">
<b><p><U><FONT COLOR="PURPLE">Welcome to online book storage.Press login if you are
having id otherwise press registration.</U></FONT></p></b></H2>
<H2><FONT COLOR="WHITE"></FONT></H2>
<H3 ALIGN="CENTER">
<A HREF="reg.html"><BR><BR><FONT
COLOR="black"><ITALIC>REGISTRATIONFORM</FONT></ITALIC><BR><BR>
<BR><BR><A HREF="profile.html"><FONT COLOR="black"><ITALIC>USER
PROFILE</FONT></ITALIC><BR>
<BR><BR><A HREF="login.html"><FONT COLOR="black"><ITALIC>USER
LOGIN</FONT></ITALIC><BR>
<BR><BR><A HREF="catalog.html"><FONT COLOR="black"><ITALIC>BOOKS
CATALOG</FONT></ITALIC><BR>
<BR><BR><A HREF="payment.html"><FONT
COLOR="black"><ITALIC>PAYMENT</FONT></ITALIC><BR>
<BR><BR><A HREF="Order.html"><FONT COLOR="black"><ITALIC>ORDER
CONFIRMATION</H3></FONT></ITALIC><BR>
</body>
</html>

Login.html
<html>
<body bgcolor="blue"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||document.myform.pwd.value=="")
{
alert("LoginId and Password must be filled")
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
window.open("catalog.html","right");
}
else
{
alert("INVALID INPUT");
//document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID:<input type="text" name="id"><br>
PASSWORD:<input type="password" name="pwd">
<br><br>
</pre>
<input type="button" value="ok" onClick="validate()">
<input type="reset" value="clear">
</div>
</form>
</body>
</html>
Reg.html:
<html>
<body bgcolor="blue"><br><br>
<script language="javascript">
var str=document.myform.phno.value;
var x;
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
NAME :<input type="text" name="name"><br>
ADDRESS :<input type="type" name="addr"><br>
CONTACT NUMBER:<input type="text" name="phno"><br>
LOGINID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>

Catalog.html:
<html>
<body bgcolor="pink"><br><br><br>
<div align="center">
<pre>
BOOK TITLE:<input type="text" name="title"><br>
</pre><br><br>
</div>
<br><br>
<div align="center">

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


<input type="reset" value="clear" name="button2">
</body>
</html>

Order.html:
<html>
<body bgcolor="pink"><br><br><br>
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
TITLE :<input type="text" name="title"><br>
NO.OF BOOKS :<input type="text" name="no"><br>
COST OF BOOK:<input type="text"name="cost"><br>
DATE :<input type="text" name="date"><br></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" name="button1">
<input type="reset" value="clear" name="button2">
</body>
</html>

Payment.html:
<html>
<body bgcolor="pink"><br><br><br>
<script language="javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||document.myform.pwd.value==""||
document.myform.amount.value==""||document.myform.num.value=="")
{
13
flag=0;
}
var str=document.myform.amount.value;
var x;
for(var i=0;i<str.length;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
str=document.myform.num.value;
for(var i=0;i<str.lenght;i++)
{
x=str.substr(i,1);
if(!(x<=9))
{
flag=0;
break;
}
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
PASSWORD :<input type="password" name="pwd"><br>
AMOUNT :<input type="text" name="amount"><br>
CREDITCARDNUMBER:<input type="PASSWORD" name="num+"><br></pre><br><br>
</div>
<br><br><div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear">
</form>
</body>
</html>
Profile.html:
<html>
<body bgcolor="pink"><br><br><br>
<script type="text/javascript">
function validate()
{
var flag=1;
if(document.myform.id.value==""||document.myform.pwd.value=="")
{
flag=0;
}
if(flag==1)
{
alert("VALID INPUT");
}
else
{
alert("INVALID INPUT");
document.myform.focus();
}
}
</script>
<form name="myform">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br>
PASSWORD:<input type="password" name="pwd"></pre><br><br>
</div>
<br><br>
<div align="center">
<input type="submit" value="ok" onClick="validate()">
<input type="reset" value="clear" >
</form>
</body>
</html>
OUTPUT:

Login.html
Profile.html
Order.html
RESULT:
Thus to write java servlet programs to install TOMCAT web server for information to the
Shopping cart was successfully executed and verified.
EX.NO.5 SESSION TRACKING USING HIDDEN FORM FIELDS

AIM:

To write a Java Program for Session Tracking Using Hidden Form Fields. This servlet
demonstrates session tracking using hidden form fields by displaying the shopping cart for a
bookworm. Note that, if you try this servlet, the buttons at the bottom of the page it generates don't
take you anywhere real.

PROCEDURE:

1. Create a web page using HTML form that contains the fields such as text, password and one
submit button.
2. Set the URL of the server as the value of form’s action attribute.
3. Ask if the user wants to add more items or check out.
4. Include the current items as hidden fields so they'll be passed on and submit to self.

PROGRAM:
register.html:

<html>
<body bgcolor = "cyan">
<center>
<h1>WELCOME TO REGISTRATION PAGE</h1>
<form action="./registerone" METHOD="post">
Name: <input type="text" name = "name"><br><br>
Password: <input type="password" name="password"><br><br>
PROFESSION:
<select name="profession">
<option value="engineer">ENGINEER</option>
<option value="teacher">TEACHER</option>
<option value="businessman">BUSINESSMAN</option>
</select><br><br>
<input type="submit" value="REGISTER">
</form>
</center>
</body>
</html>

web.xml
<web-app>
<welcome-file-list>
<welcome-file>register.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>RegistrationServletOne</servlet-name>
<servlet-class>RegistrationServletOne</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServletOne</servlet-name>
<url-pattern>/registerone</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegistrationServletTwo</servlet-name>
<servlet-class>RegistrationServletTwo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServletTwo</servlet-name>
<url-pattern>/registertwo</url-pattern>
</servlet-mapping>
</web-app>

RegistrationServletOne.java:

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;
public class RegistrationServletOne extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String name = request.getParameter("name");
String password = request.getParameter("password");
String profession = request.getParameter("profession");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor = wheat>");
out.println("<center>");
out.println("<h1>COMPLETE THE REGISTRATION</h1>");
out.println("<form action = ./registertwo method = post");
out.println("<input type = hidden name = name value =" + name + ">");
out.println("<input type = hidden name = password value =" + password + ">");
out.println("<input type = hidden name = profession value =" + profession + ">");
out.println("EMAIL ID:<input type =text name = email><br><br>");
out.println("PHONE NO:<input type =text name = cell><br><br>");
out.println("<input type =submit value=registernow>");
out.println("</center>");
out.println("</body></html>");
out.close();
}
}

RegistrationServletTwo.java
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;
public class RegistrationServletTwo extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException

{
String name = request.getParameter("name");
String password = request.getParameter("password");
String profession = request.getParameter("profession");
String email = request.getParameter("email");
String cell = request.getParameter("cell");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body bgcolor = wheat>");
out.println("<center>");
out.println("<h1>REGISTRATION SUCCESSFUL..........</h1>");
out.println("</center>");
out.println("</body></html>");
out.close();
}
RESULT:

Thus the Java program for Session Tracking using hidden form fields has been executed
successfully.
EX.NO.6 THREE TIER APPLICATIONS USING SERVLET

AIM:
To write java servlet programs to conduct online examination and to display student mark
list available in a database.

PROCEDURE:
Client:
1. In index.html on the client side declare the contents that you like to transfer to the server
using html form and input type tags.
2. Create a submit button and close all the included tags.
Server:
1. Import all necessary packages
2. Define a class that extends servlet
3. In the doPost() method, do the following:
i) Set the content type of the response to "text/html"
ii) Create a writer to the response
iii) Get a paratmeter from the request
iv) If its value is equal to right answer then add 5 to mark variable
v) Similarly repeat step
vi) for all parameters
vii) Display the result in an html format using the writer
Student Mark List Database:
1. Import necessary to java packages and javax packages and classes
2. Create a class that extends HttpServlet and implements ServletException
3. and IOException
4. In the doGet() method, do the following:
i) Create a PrintWriter object
ii) Open a connection with the data source name
iii) Write a sql query and execute to get the resultset
iv) Display the resultset information in html form.

PROGRAM:

Servlet Code:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StudentServlet3 extends HttpServlet
{
String message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5; int Total=0;
Connection connect; Statement stmt=null; ResultSet rs=null;
public void doPost(HttpServletRequest request,HttpServletResponse response) throws
ServletExcep-
tion,IOException
{
try
{
String url="jdbc:odbc:NEO"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connect=DriverManager.getConnection(url," "," "); message="Thank you for participating in online
Exam";
}
catch(ClassNotFoundException cnfex){ cnfex.printStackTrace();
}
catch(SQLException sqlex){ sqlex.printStackTrace();
}
catch(Exception excp){ excp.printStackTrace();
}
Seat_no=request.getParameter("Seat_no"); Name=request.getParameter("Name");
ans1=request.getParameter("group1"); ans2=request.getParameter("group2");
ans3=request.getParameter("group3"); ans4=request.getParameter("group4");
ans5=request.getParameter("group5"); if(ans1.equals("True"))
Total+=2;
if(ans2.equals("False"))
Total+=2;
if(ans3.equals("True"))
Total+=2;
if(ans4.equals("False"))
Total+=2;
if(ans5.equals("False"))
Total+=2; try
{
Statement stmt=connect.createStatement();
String query="INSERT INTO student("+"Seat_no,Name,Total"+") VAL-
UES('"+Seat_no+"','"+Name+"','"+Total+"')";
int result=stmt.executeUpdate(query); stmt.close();
}catch(SQLException ex){
}
response.setContentType("text/html"); PrintWriter out=response.getWriter(); out.println("<html>");
out.println("<head>"); out.println("</head>"); out.println("<body bgcolor=cyan>");
out.println("<center>"); out.println("<h1>"+message+"</h1>\n");
out.println("<h3>Yours results stored in our database</h3>"); out.print("<br><br>");
out.println("<b>"+"Participants and their Marks"+"</b>"); out.println("<table border=5>");
try
{
Statement stmt=connect.createStatement(); String query="SELECT * FROM student";
rs=stmt.executeQuery(query); out.println("<th>"+"Seat_no"+"</th>");
out.println("<th>"+"Name"+"</th>"); out.println("<th>"+"Marks"+"</th>"); while(rs.next())
{
out.println("<tr>");
out.print("<td>"+rs.getInt(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.println("</tr>");
}
out.println("</table>");
}
catch(SQLException ex){ } finally
{
try
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(connect!=null)
29
connect.close();
}
catch(SQLException e){ }
}
out.println("</center>");
out.println("</body></html>");
Total=0;
}}
HTML Code:
<html><head><title>Database Test</title></head> <body>
<center><h1>Online Examination</h1> </center>
<form action="StudentServlet3.view" method="POST"> <div align="left"><br></div>
<b>Seat Number:</b> <input type="text" name="Seat_no"> <div align="Right">
<b>Name:</b> <input type="text" name="Name" size="50"><br> </div>
<br><br>
<b>1. Every host implements transport layer.</b><br/> <input type="radio" name="group1"
value="True">True <input type="radio" name="group1" value="False">False<br>
<b>2. It is a network layer's responsibility to forward packets reliably from source to destina-
tion</b><br/>
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<b>3. Packet switching is more useful in bursty traffic</b><br/> <input type="radio"
name="group3"
value="True">True<input type="radio" name="group3" value="False">False<br> <b>4. A phone
network uses packet switching</b><br/> <input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>
<b>5. HTML is a Protocol for describing web contents</b><br/> <input type="radio"
name="group5"
value="True">True
<input type="radio" name="group5" value="False">False<br> <br><br><br>
<center>
<input type="submit" value="Submit"><br><br> </center>
</form></body></html>
OUTPUT:

RESULT:
Thus to write java servlet programs to conduct online examination and to display student
mark list available in a database was successfully executed and verified.
EX.NO.7 PROGRAMS USING XML-SCHEMA-XSLT/XSL

AIM:
To develop a program using XML-SCHEMA-XSLT/XSL.

PROCEDURE:

1.The xsl:output element specifies how to display the result tree.


2.The XSL pre-processor produces the output result tree.
3.It should specified by xsl:output element.
4.The method attribute of xsl:output specifies the overall process to produce the result tree.
5. the HTML output method results the tree as HTML document.

PROGRAM:

Students.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Students>
<Student>
<Name>ABC</Name>
<Email>[email protected]</Email>
<Age>19</Age>
</Student>
<Student>
<Name>PQR</Name>
<Email>[email protected]</Email>
<Age>19</Age>
</Student>
<Student>
<Name>XYZ</Name>
<Email>[email protected]</Email>
<Age>19</Age>
</Student>
<Student>
<Name>LMN</Name>
<Email>[email protected]</Email>
<Age>19</Age>
</Student>
</Students>

Students.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Student Information</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Email</th>
<th>Age</th>
</tr>
<xsl:apply-templates select="Students/Student" />

</table>
</body>
</html>
</xsl:template>
<xsl:template match="Student">
<tr>
<td><xsl:value-of select="Name" /></td>
<td><xsl:value-of select="Email" /></td>
<td><xsl:value-of select="Age" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>

Students.py:

!pip install lxml


from lxml import etree
# Load XML and XSL files
xml_doc = etree.parse('students.xml')
xslt_doc = etree.parse('students.xsl')
# Create a transformer
transformer = etree.XSLT(xslt_doc)
# Apply the transformation
result_tree = transformer(xml_doc)
# Save the result to an HTML file
with open('output.html', 'wb') as f:
f.write(etree.tostring(result_tree, pretty_print=True))
# Apply the transformation
result_tree = transformer(xml_doc)
# Display the result
print(str(result_tree))
Output.html:
<html><body>
<h2>Student Information</h2>
<table border="1">
<tr>
<th>Name</th>
<th>Email</th>
<th>Age</th>
</tr>
<tr>
<td>ABC</td>
<td>[email protected]</td>
<td>19</td>
</tr>
<tr>
<td>PQR</td>
<td>[email protected]</td>
<td>19</td>
</tr>
<tr>
<td>XYZ</td>
<td>[email protected]</td>
<td>19</td>
</tr>
<tr>
<td>LMN</td>
<td>[email protected]</td>
<td>19</td>
</tr>
</table>
</body></html>
OUTPUT:
RESULT:
Thus the programs using XML-schema –XSL/XSL was successfully executed and verified.

You might also like