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

WT Lab Answers

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

WT Lab Answers

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

III Semester Web Technologies MCA

1. Develop static pages (using Only HTML) of an online Book store. The pages should resemble:
www.amazon.com.The website should consists the following pages.
• Home page
• Registration
• User Login
• Books catalog
AIM: Develop static pages (using Only HTML) of an online Book store. The pages should resemble:
www.amazon.com.The website should consists the following pages.
• Home page
• Registration
• User Login
• Books catalog

PROCEDURE:
1.Home.html :

<head>
<frameset rows="20%,*">
<frame src="topframe.html"name="f1">
<frameset cols="20%,*">
<frame src="leftframe.html"name="f2">
<frame src="rightframe.html"name="f3">
</frameset>
</frameset>
</head>

Leftframe.html :

<html>
<body>
<a href="cse.html" target="f3"><h3>CSE</h3> </a>
<br><br><br><br><br>
<a href=”ece.html” target="f3"><h3>ECE</h3></a>
<br><br><br><br><br>
<a href=”eee.html” target="f3"><h3>EEE</h3></a>
<br><br><br><br><br>
<a href=”civil.html” target="f3"><h3>Civil</h3></a>
</body>
</html>

JNTUA CSE 1
III Semester Web Technologies MCA

Cse.html :

<html>
<body>
<table border=1>
<tr>
<td>
<img src="xml.jpg" height="80" width="80">
<td>Book:XML<br>
Author: James J.Maivald<br>
Publication:Adobe Press<br>
<td>$50.5
<td><input type="button" value="add to cart">
</tr>
<tr>
<td>
<img src="java.jpg" height="80" width="80">
<td>Book:Java2<br>
Author:Herbert Schilidt<br>
Publication:Mc GrawHIll<br>
<td>$120
<td><input type="button" value="add to cart">
</tr>
<tr>
<td><img src="nw.jpg" height="80" width="80">
<td>book:Network Trouble Shooting<br>
Author: Jonathan Feld man<br>
Publication:Sams<br>
<td>$40.5
<td><input type="button" value="add to cart">
</tr>
</body>
</html>

Ece.html :

<html>
<body>
<table border=1>
<tr>
<td><img src="mob.jpg" height="80" width="80">
<td>Book: Mobile Application Development<br>
Author: Mary J.Cronin<br>
Publication:Mc Graw-Hil<br>
<td>$55.5
<td><input type="button" value="add to cart">
</tr>
<tr>
<td><img src="grid.png" height="80" width="80">
<td>Book:Grid Computing<br>
Author: J.G.Hey<br>
Publication:Wiley<br>
<td>$70.4
<td><input type="button" value="add to cart">
</tr>

JNTUA CSE 2
III Semester Web Technologies MCA

<tr>
<td><img src="antenna.jpg" height="80" width="80">
<td>book:Antenna <br>
Author: HAM<br>
Publication:RElay League<br>
<td>$70.5
<td><input type="button" value="add to cart">
</tr>
</table>
</body>
</html>

Eee.html :

<html>
<body>
<table border=1>
<tr>
<td>
<img src="ele1.jpg" height="80" width="80">
<td>book:Electrical motor controls<br>
Author: Gray J.Rockis<br>
Publication:Amer Technical<br>
<td>$40.5
<td><input type="button" value="add to cart">
</tr>
<tr>
<td><img src="ele2.jpg" height="80" width="80">
<td>Book:Electrical Engineering<br>
Author: John G.Webster<br>
Publication:Wiley<br>
<td>$80.4
<td><input type="button" value="add to cart">
</tr>
<tr>
<td><img src="ele3.jpg" height="80" width="80">
<td>Book:Foundations ofElectrical Engineering<br>
Author: John R.Coqdell<br>
Publication:Prentice Hall<br>
<td>$40.5
<td><input type="button" value="add to cart">
</tr>
</table>
</body>
</html>

JNTUA CSE 3
III Semester Web Technologies MCA

Civil.html :

<html>
<body>
<table border=1>
<tr>
<td>
<img src="civil1.jpg" height="80" width="80">
<td>Book:Concrete Technology<br>
Author: S.Chand<br>
Publication:S.Chand<br>
<td>$60.5
<td><input type="button" value="add to cart">
</tr>
<tr>
<td>
<img src="civil2.jpg" height="80" width="80">
<td>Book:Civil Engineering<br>
Author: Michael <br>
Publication:Professional <br>
<td>$30.4
<td><input type="button" value="add to cart">
</tr>
</table>
</body>
</html>

rightframe.html :

<html>
<body bgcolor="pink">
<p>
<h2 align="center"> <font face="times new roman" color="green">
Online book store information </font> </h2>
<h3> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<font face="monotype corsiva" color=blue>
This is the online book store developed by students of jntu.
It contains book catalogue of various branches like cse,ece,eee,civil </font></h3>
</p>
</body>
</html>

JNTUA CSE 4
III Semester Web Technologies MCA

Catalogue.html :

<html>
<body>
<center>
<table border=1>
<tr>
<th> Book Preview </th>
<th> Book Details </th>
<th> Price </th>
<th> Payment </th>
</tr>
<tr><td> <img src="2.jpg" width=100 height=100> </img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="green" >
book:XML Bible
Author:winston
Publisher:Wiesley
</font>
</pre>
</td>
<td>&nbsp;$40 &nbsp; </td>

<td> &nbsp; &nbsp; <a href="cart.html" target="_blank">


<img src="cart.jpg" width="100" height="50"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
<tr><td> <img src="5.jpg" width=100 height=100>
</img>
</td>
<td>
<pre>
<font face="comic sans ms" size=4 color="green" >
book:Java 2
Author:Watson
Publisher:BPB publications
</font>
</pre>
</td>
<td>&nbsp; $40 &nbsp;</td>
<td> &nbsp; &nbsp;
<a href="cart.html" target="_blank">
<img src="cart.jpg" width="100" height="50"></img>
</a> &nbsp; &nbsp;
</td>
</tr>
</table> </center>
</body>
</html>

JNTUA CSE 7
III Semester Web Technologies MCA

Registration.html :

<html>
<body>
<center>
<h1>Registration page</h1>
<form>
<label>name</label>
<input type="text" size="20"><br><br> <br>
<label>password</label>
<input type="password" size="20" maxsize="28"><br> <br> <br>
<label>email</label>
<input type="text" size="30"><br> <br> <br>
<label>phone no</label>
<input type="text" size="2">
<input type="text" size="6">
<input type="text" size="10"><br> <br> <br>
<label>Sex</label>
<input type="radio" name="sex">m
<input type="radio" name="sex">f <br> <br> <br>
<label> date of birth</label>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select>
<option>jan</option>
<option>feb</option>
<option>mar</option>
<option>apr</option>
</select>
<select>
<option>1980</option>
<option>1981</option>
<option>1982</option>
<option>1983</option>
</select> <br> <br> <br>
<label> Languages Known </label> &nbsp; &nbsp;
<input type="checkbox"> English &nbsp; &nbsp;&nbsp;
<input type="checkbox"> Telugu &nbsp; &nbsp; &nbsp;
<input type="checkbox"> Hindi &nbsp; &nbsp; &nbsp;
<input type="checkbox"> Tamil <br> <br> <br>
<label> Address </label>
<textarea rows=5 cols=20 scrolling="yes"> </textarea>
</center>
</body>
</html>

JNTUA CSE 10
III Semester Web Technologies MCA

2. Develop static pages (using only HTML) of an online Book store. The pages should resemble:
www.amazon.com. The website should consists of the following pages.
• Home page
• Registration and user Login
• User profile page
• Books catalog
• Shopping cart
• Payment by credit cardtt
• Order Conformation

Validate the Registration, user login, user profile and payment by credit card pages using
JavaScript.
AIM: Develop static pages (using only HTML) of an online Book store. The pages should resemble:
www.amazon.com. The website should consists of the following pages.
• Home page
• Registration and user Login
• User profile page
• Books catalog
• Shopping cart
• Payment by credit cardtt
• Order Conformation

Validate the Registration, user login, user profile and payment by credit card pages using JavaScript.

Main.html:
<frameset rows=”25%, 75 %”>
<frame src=”top.html” name=”top”>
<frameset cols=”25%,75%”>
<frame src=”left.html” name=”left”>
<frame src=”right.html” name=”right”>
</frameset>
</frameset>
Top.html:
<html>
<body bgcolor=”pink”>
<br><br>
<marquee><h1 align=”center”><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>
</body>
</html>
Right.html:
<html>
<body bgcolor=”pink”>
<br><br><br><br><br>
<h2 align=”center”>
<b><p> welcome to online book storage. Press login if you are
having id otherwise press registration.
</p></b></h2>
</body>
</html>
Left.html:

JNTUA CSE 12
III Semester Web Technologies MCA

<html>
<body bgcolor=”pink”>
<h3>
<ul>
<li><a href=”login.html” target=”right”><font color=”black”>
LOGIN</font></a></li><br><br>
<li><a href=”reg.html” target=”right”><font color=”black”>
REGISTRATION</font></a></li><br><br>
<li><a href=”profile.html”
target=”right”><fontcolor=”black”> USER
PROFILE</font></a></li><br><br>
<li><a href=”catalog.html” target=”right”><fontcolor=”black”>
BOOKS CATALOG</font></a></li><br><br>
<li><a href=”scart.html” target=”right”><font color=”black”>
SHOPPINGCART</font></a></li><br><br>
<li><a href=”payment.html” target=”right”><fontcolor=”black”>
PAYMENT</font></a></li><br><br>
<li><a href=”order.html” target=”right”><font color=”black”>
ORDER CONFIRMATION</font></a></li><br><br>
</ul>
</body>
</html>

JNTUA CSE 13
III Semester Web Technologies MCA

Login.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==” “)
{
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()”>&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;<input type=”reset” value=”clear”>
</form>
</body>
</html>

JNTUA CSE 14
III Semester Web Technologies MCA

Reg.html:
<html>
<body bgcolor=”pink”><br><br>
<script language=”javascript”>
function validate()
{
var flag=1;
if(document.myform.name.value==””||
document.myform.addr.value==””||
document.myform.phno.value==””||
document.myform.id.value==””||
document.myform.pwd.value==””)
{
flag=0;
}
var str=document.myform.phno.value;
var x;
for(var i=0;i<str.length;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>
NAME :<input type="text" name="name"><br>
ADDRESS :<input type="type" name="addr"><br>
CONTACT NUMBER:<iput 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()">&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear">
</form></body></html>

JNTUA CSE 15
III Semester Web Technologies MCA

}
}
</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()">&nbsp;&nbsp;&nbsp;&nbsp; <input type="reset"
value="clear" >
</form>
</body>
</html>

JNTUA CSE 21
III Semester Web Technologies MCA

3. Create and save an XML document at the server, which contains 10 users information. Write a
program, which takes User Id as an input and returns the user details by taking the user information
from the XML document.

CSSDemo.xml :

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


<?xml-stylesheet type="text/css" href="library.css"?>
<!DOCTYPE Catalog SYSTEM "Catalog.dtd">
<Catalog>
<Book>
<Title> XML Bible</Title>
<Author> Winston</Author>
<Publication>Willy</Publication>
<Edition>5 th </Edition>
<ISBN>7989</ISBN>
<Price>$56</Price>
</Book>
<Book>
<Title> artificial intelligence</Title>
<Author> srussel</Author>
<Publication> princeton hall</Publication>
<Edition>6 th </Edition>
<ISBN>79895</ISBN>
<Price>$70</Price>
</Book>
<Book>
<Title> java2</Title>
<Author> Watson</Author>
<Publication>bpb publications</Publication>
<Edition>2 th </Edition>
<ISBN>798978</ISBN>
<Price>$76</Price>
</Book>
<Book>
<Title>html in 24 hours</Title>
<Author> sams peter</Author>
<Publication>sam publication</Publication>
<Edition>5 th </Edition>
<ISBN>8989</ISBN>
<Price>$96</Price>
</Book>
</Catalog>

JNTUA CSE 22
III Semester Web Technologies MCA

Library.css :

Catalog
{
font-family:arial;
color:red;
font-size:16pt
}
Book
{
display:block;
font-family:times new roman;
color:blue;
font-size:14pt
}
Title
{
font-family:arial;
color:maroon;
font-size:12pt
}
Author
{
font-family:arial;
color:magenta;
}
Publication,Edition,ISBN,Price
{
display:block;
font-family:arial;
color:black;
font-size:10pt;
margin-left:20pt
}

Catalog.dtd :

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


<!ELEMENT Catalog (Book)*>
<!ELEMENT Book (Title, Author, Publication, Edition, ISBN, Price)>
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Author (#PCDATA)>
<!ELEMENT Publication (#PCDATA)>
<!ELEMENT Edition (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT Price (#PCDATA)>

JNTUA CSE 23
III Semester Web Technologies MCA

<title>Java2</title>
<author>Watson</author>
<publication>BPB Publications</publication>
<edition>Third edition</edition>
<isbn>0-3434-760-7</isbn>
<price>$81</price>
</book>
<book>
<title>HTML in 24 hours</title>
<author>Sam peter</author>
<publication>sam publications</publication>
<edition>fifth edition</edition>
<isbn>0-73342-760-7</isbn>
<price>$50</price>
</book>
</catalog>

Catalog_XSL.xsl :

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<center>
<h2> Books information</h2>
<table border="1">
<tr bgcolor="gray">
<th>TITLE</th>
<th>author</th>
<th>publication</th>
<th>isbn</th>
<th>edition</th>
<th>price</th>
</tr>
<xsl:for-each select="catalog/book">
<tr>
<td bgcolor="green"><xsl:value-of select="title"/></td>
<td bgcolor="red"><b>
<xsl:value-of
select="translate(author,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</b>
</td>
<td bgcolor="green"><xsl:value-of select="publication"/></td>
<td bgcolor="green"><xsl:value-of select="isbn"/></td>
<td bgcolor="green"><xsl:value-of select="edition"/></td>
<td bgcolor="green"><xsl:value-of select="price"/></td>
</tr>
</xsl:for-each>
</table>

JNTUA CSE 25
III Semester Web Technologies MCA

*4. Bean Assignments


a. Create a JavaBean which gives the exchange value of INR(Indian Rupees) into equivalent
American/Canadian/Australian Dollar value.

Indian.java :
package currency;
import java.beans.*;
import java.awt.*;
import java.awt.event.*;
public class Indian extends Canvas
{
private double rupees;
private String other;
public Indian()
{
setSize(200,25);
other="America";
}
public void setRupees(double amount)
{
rupees=amount;
repaint();
}
public double getRupees()
{
return rupees;
}
public void setOther(String other)
{
this.other=other;
repaint();
}
public String getOther()
{
return other;
}
public void paint(Graphics g)
{
if(other.equals("America"))
{
g.drawString(String.valueOf(rupees/42),20,20);
}
elseif(other.equals("Australia"))
{
g.drawString(String.valueOf(rupees/27),20,20);
19
19
}
else
if(other.equals("Canada"))
{
g.drawString(String.valueOf(rupees/35),20,20);
}
else
g.drawString("I Can't convert for such country",20,20);

JNTUA CSE 27
III Semester Web Technologies MCA

b.Create a simple Bean with a label - which is the count of number of clicks. Than create a BeanInfo
class such that only the “count” property is visible in the Property Window.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ClickCounter implements ActionListener
{
private int i = 0;
private JLabel label;
private JButton plus;
private JButton moins;

public JPanel getPanel() {


JPanel panel = new JPanel();
plus = new JButton("+");
plus.addActionListener(this);
panel.add(plus);
moins = new JButton("-");
moins.addActionListener(this);
panel.add(moins);
label = new JLabel("" + i);
panel.add(label);

return panel;
}

public void actionPerformed(ActionEvent e) {


if (e.getSource() == plus) {
i++;
label.setText("" + i);
}
else {
i--;
label.setText("" + i);
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("Click Counter");
frame.setSize(new Dimension(250, 80));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ClickCounter counter = new ClickCounter();
JPanel counterPanel = counter.getPanel();
Container content = frame.getContentPane();
content.add(counterPanel, BorderLayout.CENTER);
frame.setVisible(true);
}
}

JNTUA CSE 30
III Semester Web Technologies MCA

d.Create two Beans Traffic Light(Implemented as a Label with only three background colours-
Red,Green,Yellow) and Automobile(Implemented as a TextBox which states its state/movement). The
state of the Automobile should depend on the following Light Transition Table.
Light Transition Automobile State
Red ---> Yellow Ready
Yellow ---> Green Move
Green --> Red Stopped

TrafficPerson.java:
package demo;
import java.awt.Panel;
import java.awt.event.*;
import java.io.PrintStream;
import java.io.Serializable;
import javax.swing.JTextField;
import java.beans.*;
public class TrafficPerson extends Panel implements Serializable, PropertyChangeListener
{
public TrafficPerson()
{
tx = new JTextField(12);
state="Ready";
tx.setHorizontalAlignment(JTextField.LEFT);
tx.setText("Ready");
tx.setEnabled(false);
add(tx);
}
public void change()
{
if(state.equals("Ready"))
{
state="Move";
tx.setText(state);
}
elseif(state.equals("Move"))
{
state="Stopped";
tx.setText(state);
}
elseif(state.equals("Stopped"))
{
state="Ready";
tx.setText(state);
}
}
public void propertyChange(PropertyChangeEvent e)
{
change();
}

private JTextField tx;

private String state;


}

JNTUA CSE 32
III Semester Web Technologies MCA

TraficLight .java:
package mypack;
import java.awt.*;
import java.beans.*;
import java.io.*;
import java.util.Date;
public class TrafficLight extends Panel implements Runnable, Serializable, PropertyChangeListener
{
public TrafficLight()
{
setSize(50, 50);
color = Color.red;
label = new Label();
label.setSize(100,100);
label.setBackground(Color.red);
add(label);
changes = new PropertyChangeSupport(this);
changes.addPropertyChangeListener(this);
interval = 5;
runner = new Thread(this);
runner.start();
}

public void addPropertyChangeListener(PropertyChangeListener propertychangelistener)


{
changes.addPropertyChangeListener(propertychangelistener);
}
public void removePropertyChangeListener(PropertyChangeListener propertychangelistener)
{
changes.removePropertyChangeListener(propertychangelistener);
}
public int getInterval()
{
return interval;
}
public void setInterval(int i)
{
interval = i;
if(runner != null)
runner.interrupt();
}
public int getSeconds()
{
return (int)((new Date()).getTime() / 1000L);
}
public void run()
{

int i = getSeconds();

do
{
try
{

JNTUA CSE 33
III Semester Web Technologies MCA

Setting and Updating Password:

Set.php:

update user set password=PASSWORD(“root") where User='root';


<?php
$servername = "localhost";
$username = "root";
$password = "";

try {
$conn = new PDO("mysql:host=$servername;dbname=WebTechnologies", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>

JNTUA CSE 60
III Semester Web Technologies MCA

Deleting the Records:

Delete.php:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "WebTechnologies";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "DELETE FROM Students1 WHERE id=1";
if ($conn->query($sql) ==TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
?>

JNTUA CSE 64
III Semester Web Technologies MCA

ADDITIONAL PROGRAMS:

1. Write an HTML page including any required Javascript that takes a number from one text field in
the range of 0 to 999 and shows it in another text field in words. If the number is out of range, it
should show “out of range” and if it is not a number, it should show “not a number” message in the
result box.
Numbers.html:
<html>
<head>
<title>Number in words</title>
<script language="javascript">
function convert()
{
var num=document.forms["frm1"].num.value;
document.forms["frm1"].words.value="";
if(isNaN(num))
{
alert("Not a Number");
}
else if (num<0 || num>999)
{
alert("Out of Range");
}
else
{
var len=num.length;
var words="";
for(var i=0;i<len;i++)
{
var n=num.substr(i,1);
switch(n)
{
case '0':words+="Zero ";break;

JNTUA CSE 65
III Semester Web Technologies MCA

case '1':words+="One ";break;


case '2':words+="Two ";break;
case '3':words+="Three ";break;
case '4':words+="Four ";break;
case '5':words+="Five ";break;
case '6':words+="Six ";break;
case '7':words+="Seven ";break;
case '8':words+="Eight ";break;
default:words+="Nine ";
}
}
document.forms["frm1"].words.value=words;
}
}
</script>
</head>
<body>
<form name="frm1">
<center><h3>NUMBER IN WORDS</h3></center>
<br/>
<center>Enter a Number :<input type="text" name="num"</input><br/></center>
<br/>
<center><input type="button" name="inwords" value="In Words"
onclick="convert()"></input></center>
<br/><br/><center>Number in Words :<input type="text" name="words"</input></center>
<br/>
</form>
</body>
</html>

JNTUA CSE 66
III Semester Web Technologies MCA

Output:

JNTUA CSE 67
III Semester Web Technologies MCA

3.Write a simple calculator servlet that takes two numbers and an operator (+, -, /, * and %) from an
HTML page and returns the result page with the operation performed on the operands. It should
check in a database if the same expression is already computed and if so, just return the value from
database. Use MySQL or PostgreSQL.(Do the same problem using PHP)

Index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome</title>
</head>
<body>
<h3>Please Enter Two Numbers :::</h3>
<form method="GET" action="Cal">
Number:<input type="text" id="t1" name="t1"/><br/>
<select name="op">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="%">%</option>
</select></br>
Number:<input type="text" id="t2" name="t2">
<input type="submit" value="calculate"/></br>
</form>
</body>
</html>
Cal.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 Cal extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter pw= response.getWriter();
int n1 = Integer.parseInt(request.getParameter("t1"));
int n2 = Integer.parseInt(request.getParameter("t2"));
String op=request.getParameter("op");
if(op.equals("+")){pw.println("Addition :::"+(n1+n2));
}
else if(op.equals("-"))
{
pw.println("Subtraction :::"+(n1-n2));
}
else if(op.equals("*"))

JNTUA CSE 68
III Semester Web Technologies MCA

{
pw.println("Multiplication :::"+(n1*n2));
}
else if(op.equals("/"))
{
pw.println("Division :::"+(n1/n2));
}
else{pw.println("Remainder :::"+(n1%n2));
}
pw.close();
}
}

Output:

JNTUA CSE 69
III Semester Web Technologies MCA

4.Write an HTML page that contains a list of 5 countries. When the user selects a country, its capital
should be printed next to the list. Add CSS to customize the properties of the font of the capital
(color, bold and font size).

<!DOCTYPE html>
<html>
<head>
<title>Try me</title>
</head>
<body>
<header>
FIRST PROGRAM IN PHP
</header>
<hr>/
<?php // form field ?>
<fieldset class>
<legend>ENTER THE COUNTRY HERE</legend>
<form action="display.php" method="get">
<label>What are ur Hobies?</label>
<select name="name">
<option value="INDIA: New delhi">India</option>
<option value="Afganistan: Kabul">Afganistan</option>
<option value="Sri Lanka: Colombo">Sri Lanka</option>
<option value="Russia: Moscow">Russia</option>
<option value="U.S.A: Washiton DC">U.S.A</option>
</select>
<input id="button" type="submit" name="submit" value="Submit" size="10">
</form>
</fieldset>
</body>
</html>

Output:

JNTUA CSE 71
III Semester Web Technologies MCA

5. Write a servlet that takes name and age from an HTML page. If the age is less than 18, it should
send a page with “Hello <name>, you are not authorized to visit this site” message, where <name>
should be replaced with the entered name. Otherwise it should send “Welcome <name> to this site”
message. (Do the same problem using PHP)

A3.html

<html>
<head>
<title>User Information</title>
<table border=1>
<form method=post action="A3.php">
<tr><th>Enter User Name :</th><td><input type=text name=t1></td></br>
<tr><th>Enter User Age :</th><td><input type=text name=t2></td></br>
</table>
<input type=submit value=submit>
</form>
</center>
</head>
</html>

Output:

JNTUA CSE 72
III Semester Web Technologies MCA

A3.php

<?php
$name=$_POST['t1'];
$age=$_POST['t2'];

if($age<18)
{
echo "Hello <b>$name</b> and u are not Authorized to visit this site ";
}
else
{
echo "Welcome <b>$name</b> to this Site ";
}
?>
Output:

JNTUA CSE 73
III Semester Web Technologies MCA

6.Write a calculator program in HTML that performs basic arithmetic operations (+, -, /, * and %).
Use CSS to change the foreground and background color of the values, buttons and result display
area separately. Validate the input strings using JavaScript regular expressions. Handle any special
cases like division with zero reasonably. The screen may look similar to the following:
Value 1 Operator Value 2 Result
+ =

Sample calculator.html:
<html>
<head>
<title>
CALCULATOR</title>
<script>
function cal()
{
var a=parseInt(document.f2.num1.value);
var b=parseInt(document.f2.num2.value);
var op=document.f2.coun.value;
var res1;
switch(op)
{
case '+': res1 = a +b;
break;
case '-': res1 = a-b;
break;
case '*': res1 = a*b;
break;
case '/': res1 = a/b;
break;
case '%': res1 = a%b;
break;
}
f2.res.value=res1;
}
</script>
</head>
<body>
<form name="f2">
value1<input type=text name=num1>
operater<select name="coun">
<option >+</option>
<option >-</option>
<option >*</option>
<option >/</option>
<option >%</option>
</select>
value2<input type=text name=num2>
<input type=button value="=" onclick="cal()">
result<input type=text name=res>
</form>

JNTUA CSE 74
III Semester Web Technologies MCA

</body>
</html>

Output:

JNTUA CSE 75
III Semester Web Technologies MCA

7.Write a Java Application that will read an XML file that contains personal information (Name,
Mobile Number, age and place. It reads the information using SAX parser. After reading the
information, it shows two input Text Fields in a window, one for tag name and the other for value.
Once these two values are given, it should list all the records in the XML file that match the value of
the given field in a text area (result box). For example, if the two text boxes are entered with “name”
and “ABCD” then it should show all the records for which name is “ABCD”? An Illustration is
given below that takes a mobile number and lists all the records that have the same mobile number.

gfg.xml:

<?xml version="1.0"?>
<class>
<geek>
<id>1</id>
<username>geek1</username>
<EnrolledCourse>D.S.A</EnrolledCourse>
<mode>online self paced</mode>
<duration>Lifetime</duration>
</geek>

<geek>
<id>2</id>
<username>geek2</username>
<EnrolledCourse>System Design</EnrolledCourse>
<mode>online live course</mode>
<duration>10 Lectures</duration>
</geek>

<geek>
<id>3</id>
<username>geek3</username>
<EnrolledCourse>Competitive Programming</EnrolledCourse>
<mode>online live course</mode>
<duration>8 weeks</duration>
</geek>

<geek>
<id>4</id>
<username>geek4</username>
<EnrolledCourse>Complete Interview Preparation</EnrolledCourse>
<mode>online self paced</mode>
<duration>Lifetime</duration>
</geek>

JNTUA CSE 76
III Semester Web Technologies MCA

</class>

GfgXmlExtractor.java

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
public class GfgXmlExtractor {
public static void main(String argv[])
{
try {

File file = new File("gfg.xml");

DocumentBuilderFactory dbf
= DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);

doc.getDocumentElement().normalize();
System.out.println(
"Root element: "
+ doc.getDocumentElement().getNodeName());

NodeList nodeList
= doc.getElementsByTagName("geek");

for (int i = 0; i < nodeList.getLength(); ++i) {


Node node = nodeList.item(i);
System.out.println("\nNode Name :"
+ node.getNodeName());
if (node.getNodeType()
== Node.ELEMENT_NODE) {
Element tElement = (Element)node;
System.out.println(
"User id: "
+ tElement
.getElementsByTagName("id")
.item(0)
.getTextContent());

JNTUA CSE 77
III Semester Web Technologies MCA

System.out.println(
"User Name: "
+ tElement
.getElementsByTagName(
"username")
.item(0)
.getTextContent());
System.out.println(
"Enrolled Course: "
+ tElement
.getElementsByTagName(
"EnrolledCourse")
.item(0)
.getTextContent());
System.out.println(
"Mode: "
+ tElement
.getElementsByTagName("mode")
.item(0)
.getTextContent());
System.out.println(
"Duration: "
+ tElement
.getElementsByTagName(
"duration")
.item(0)
.getTextContent());
}
}
}

catch (Exception e) {
System.out.println(e);
}
}
}

JNTUA CSE 78
III Semester Web Technologies MCA

9.Consider the following web application for implementation:


The user is first served a login page which takes user's name and password. After submitting the
details the server checks these values against the data from a database and takes the following
decisions.
If name and password matches, serves a welcome page with user's full name.
If name matches and password doesn't match, then serves “password mismatch” page
If name is not found in the database, serves a registration page, where users full name, present user
name (used to login) and password are collected

Form3.html

<form action='home.php' method='post'>


Login<br>
User name: <input type='text' name='user'><br>
Password: <input type='password' name='pass'><br>
<input type='submit'value='Login'>
</form>

JNTUA CSE 80
III Semester Web Technologies MCA

Home.php

<?php
session_start();
$user = $_POST['user'];
$pass = $_POST['pass'];
$_SESSION['luser'] = $user;
$_SESSION['lpass'] = $pass;
$server = "localhost";
$username = "root";
$password = "mysql";
$database = "users";
$tablename = "fulluser";
if ($user&&$pass)
{
$connect = mysql_connect($server,$username,$password) or die("not connecting");
mysql_select_db($database) or die("no db :");
$query = mysql_query("SELECT * FROM $tablename WHERE username='$user' and
password='$pass'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
print "Hello " . $row['firstname'] . " " . $row['middlename'] . " " . $row['lastname'];
}
}
$query = mysql_query("SELECT * FROM $tablename WHERE username='$user' and
password!='$pass'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
print "Password is wrong";
}
$query = mysql_query("SELECT * FROM $tablename WHERE username='$user'");
$numrows = mysql_num_rows($query);
if ($numrows==0)
{
header("Location:http://localhost/test/prg8/reg.php");
}
}
else
die("please enter a username and password!");
?>

JNTUA CSE 81
III Semester Web Technologies MCA

10. Implement a simple arithmetic calculator with +, -, /, *, % and = operations using Struts
Framework The number of times the calculator is used should be displayed at the bottom (use
session variable).
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class calculator implements ActionListener {


private static JTextField inputBox;

calculator(){}
public static void main(String[] args) {
createWindow();
}

private static void createWindow() {


JFrame frame = new JFrame("calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

createUI(frame);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

private static void createUI(JFrame frame) {

JNTUA CSE 83
III Semester Web Technologies MCA

JPanel panel = new JPanel();


calculator calculator = new calculator();
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
panel.setLayout(layout);

inputBox = new JTextField(10);


inputBox.setEditable(false);

JButton button0 = new JButton("0");JButton button1 = new JButton("1");


JButton button2 = new JButton("2");JButton button3 = new JButton("3");
JButton button4 = new JButton("4");JButton button5 = new JButton("5");
JButton button6 = new JButton("6");JButton button7 = new JButton("7");
JButton button8 = new JButton("8");JButton button9 = new JButton("9");

JButton buttonPlus = new JButton("+");JButton buttonMinus = new JButton("-");


JButton buttonDivide = new JButton("/");JButton buttonMultiply = new JButton("x");
JButton buttonClear = new JButton("C");JButton buttonDot = new JButton(".");
JButton buttonEquals = new JButton("=");

button1.addActionListener(calculator);button2.addActionListener(calculator);
button3.addActionListener(calculator);button4.addActionListener(calculator);
button5.addActionListener(calculator);button6.addActionListener(calculator);
button7.addActionListener(calculator);button8.addActionListener(calculator);
button9.addActionListener(calculator);button0.addActionListener(calculator);

buttonPlus.addActionListener(calculator);buttonMinus.addActionListener(calculator);
buttonDivide.addActionListener(calculator);buttonMultiply.addActionListener(calculator);
buttonClear.addActionListener(calculator);buttonDot.addActionListener(calculator);
buttonEquals.addActionListener(calculator);

gbc.fill = GridBagConstraints.HORIZONTAL;

JNTUA CSE 84
III Semester Web Technologies MCA

gbc.gridx = 0; gbc.gridy = 0; panel.add(button1, gbc);


gbc.gridx = 1; gbc.gridy = 0; panel.add(button2, gbc);
gbc.gridx = 2; gbc.gridy = 0; panel.add(button3, gbc);
gbc.gridx = 3; gbc.gridy = 0; panel.add(buttonPlus, gbc);
gbc.gridx = 0; gbc.gridy = 1; panel.add(button4, gbc);
gbc.gridx = 1; gbc.gridy = 1; panel.add(button5, gbc);
gbc.gridx = 2; gbc.gridy = 1; panel.add(button6, gbc);
gbc.gridx = 3; gbc.gridy = 1; panel.add(buttonMinus, gbc);
gbc.gridx = 0; gbc.gridy = 2; panel.add(button7, gbc);
gbc.gridx = 1; gbc.gridy = 2; panel.add(button8, gbc);
gbc.gridx = 2; gbc.gridy = 2; panel.add(button9, gbc);
gbc.gridx = 3; gbc.gridy = 2; panel.add(buttonDivide, gbc);
gbc.gridx = 0; gbc.gridy = 3; panel.add(buttonDot, gbc);
gbc.gridx = 1; gbc.gridy = 3; panel.add(button0, gbc);
gbc.gridx = 2; gbc.gridy = 3; panel.add(buttonClear, gbc);
gbc.gridx = 3; gbc.gridy = 3; panel.add(buttonMultiply, gbc);
gbc.gridwidth = 3;

gbc.gridx = 0; gbc.gridy = 4; panel.add(inputBox, gbc);


gbc.gridx = 3; gbc.gridy = 4; panel.add(buttonEquals, gbc);
frame.getContentPane().add(panel, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e) {


String command = e.getActionCommand();
if (command.charAt(0) == 'C') {
inputBox.setText("");
}else if (command.charAt(0) == '=') {
inputBox.setText(evaluate(inputBox.getText()));
}else {
inputBox.setText(inputBox.getText() + command);
}

JNTUA CSE 85
III Semester Web Technologies MCA

public static String evaluate(String expression) {


char[] arr = expression.toCharArray();
String operand1 = "";String operand2 = "";String operator = "";
double result = 0;

for (int i = 0; i < arr.length; i++) {


if (arr[i] >= '0' && arr[i] <= '9' || arr[i] == '.') {
if(operator.isEmpty()){
operand1 += arr[i];
}else{
operand2 += arr[i];
}
}

if(arr[i] == '+' || arr[i] == '-' || arr[i] == '/' || arr[i] == '*') {


operator += arr[i];
}
}

if (operator.equals("+"))
result = (Double.parseDouble(operand1) + Double.parseDouble(operand2));
else if (operator.equals("-"))
result = (Double.parseDouble(operand1) - Double.parseDouble(operand2));
else if (operator.equals("/"))
result = (Double.parseDouble(operand1) / Double.parseDouble(operand2));
else
result = (Double.parseDouble(operand1) * Double.parseDouble(operand2));
return operand1 + operator + operand2 + "=" +result;
}
}

JNTUA CSE 86
III Semester Web Technologies MCA

Output:

JNTUA CSE 87

You might also like