IT LAB PROGRAMS 11-20
11. Design an XML document to store information about a student in a
college and display it.
Xml file
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="[Link]"?>
<STUDENT_DATA>
<STUDENT>
<USN>USN: 1111111</USN>
<NAME>NAME: Anurag</NAME>
<COLLEGE>COLLEGE: Presidency</COLLEGE>
<EMAIL>E-MAIL: anurag@[Link]</EMAIL>
</STUDENT>
<STUDENT>
<USN>USN: 2222222</USN>
<NAME>NAME: Kevin</NAME>
<COLLEGE>COLLEGE: USC</COLLEGE>
<EMAIL>E-MAIL: kevin@[Link]</EMAIL>
</STUDENT>
</STUDENT_DATA>
CSS FILE
*{
display: block;
font-size: 20px;
USN{
color: blue;
font-size: 30px;
margin-top: 20px;
}
12. Design signup form to validate username, password, and phone numbers
etc using Java script.
HTML FILE
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form</title>
</head>
<body>
<script>
function validateForm(){
var name = [Link]("name").value;
var password = [Link]("password").value;
var phoneno = [Link]("phoneno").value;
if(name==null || name==""){
alert("name cant be empyt");
return false;
if([Link] < 6){
alert("password must be 6 character long");
return false
if([Link] != 10){
alert("phone number must be 10 digits");
return false
[Link]("output").innerHTML = "You are valid user";
</script>
<form>
Name: <input type="text" id="name"><br>
Password: <input type="password" id="password"><br>
Phone Number: <input type="text" id="phoneno"><br>
<input type="button" onclick="validateForm()" value="submit">
<h1 id="output"></h1>
</form>
</body>
</html>
13. Write a JavaScript program to determine whether a given year is a leap
year.
HTML FILE
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript to check leap year</title>
</head>
<body>
Enter Year: <input type="text" id="year">
<input type="button" id="button" value="check" onclick="leapYear()">
<h2 id="output"></h2>
<script>
function leapYear(){
var year = [Link]("year").value;
var result = (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
if(result == true){
[Link]("output").innerHTML = "It is a leap year";
else{
[Link]("output").innerHTML = "It is a not leap year";
</script>
</body>
</html>
14. Write a JavaScript program to convert temperatures to and from celsius,
Fahrenheit
HTML FILE
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<h2>JS Celcius to Farahnit</h2>
<p>Enter number</p>
<input type="number" id="c" onkeyup="convert('c')"> Degree Celcius<br>
<input type="number" id="f" onkeyup="convert('f')"> Degree Farahnit<br>
<p><b>Note: </b> [Link]() is used to return</p>
<script>
function convert(degree){
var x;
if(degree == 'c'){
x = [Link]("c").value * 9/5 + 32;
[Link]("f").value = x;
else{
x = ([Link]("f").value-32) * 5/9;
[Link]("c").value = x;
</script>
</body>
</html>
15. Write a JavaScript program to use pi value as global variable and print the
area of circle.
HTML FILE
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Area Of A Circle</h1>
Enter the Radius: <input type="text" name="text" id="radius">
<input type="button" value="calculate" onclick="calculate()">
<script>
var pi = 3.14;
function calculate(){
var radius = [Link]("radius").value;
alert("The Area of the circle is " + (radius*radius*pi));
</script>
</body>
</html>
16. Write servlet application to print current date & time.
SERVLET FILE
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
@WebServlet("/DateTime")
public class DateTime extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter pw = [Link]();
[Link] date = new [Link]();
[Link]("<h2>Current Date and Time" + [Link]() + "</h2>");
[Link]();
17. Write a servlet code to demonstrate session tracking.
FIRST SERVLET FILE
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet("/FirstServlet")
public class FirstServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
String n = [Link]("uname");
[Link]("Welcome " + n);
Cookie ck = new Cookie("uname", n);
[Link](ck);
[Link]("<h1> This is 1st Servlet</h1>");
[Link]("<form action='SecondServlet'>");
[Link]("<input type='submit' value='go'>");
[Link]("</form>");
[Link]();
SECOND SERVLET FILE
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet("/SecondServlet")
public class SecondServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<h1> This is second<h1>");
Cookie ck[] = [Link]();
[Link]("Hello " + ck[0].getValue());
[Link]();
HTML FILE
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="FirstServlet" method="post">
Name:<input type="text" name="uname"><br>
<input type="submit">
</form>
</body>
</html>
18. Write a Java Program to Implement Helloworld program using servlets.
SERVLET FILE
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet("/Hello")
public class Hello extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("Hello world");
[Link]();
19. Write a JSP Program using Expression, Scriplet and Directive.
JSP FILE
<%@page import="[Link]" %>
<!DOCTYPE html>
<html>
<head>
<title>Scripting Tags</title>
</head>
<body>
convert a string to upper case:
<% new String("HelloWorld").toUpperCase(); %>
<%
for(Month month:[Link]()){
[Link]("<br>"+month);
%>
<%!
int cube(int n){
return n*n*n;
%>
<% [Link]("<br> Cube of 3 is: " + cube(3));
%>
</body>
</html>
20. Write a JSP program to demonstrate database connectivity.
JSP FILE
<%@page import = "[Link].*" %>
<%@page import = "[Link].*" %>
<html>
<head>
<title>Connection with mysql database</title>
</head>
<body>
<h1>Connection Status</h1>
<%
try{
String connectionUrl = "jdbc:mysql://localhost:3306/test";
Connection connect = null;
[Link]("[Link]").newInstance();
connect = [Link](connectionUrl, "root", "");
if(![Link]()){
[Link]("Successfully connected to " + "MySQL server
using TCP/IP...");
[Link]();
catch(Exception ex){
[Link]("Unable to connect to Database");
%>
</body>
</html>