Dept HTML
Dept HTML
html
Dec.html
Output:
Home.html:
Output:
Output:
WEEK 2: Write JavaScript to validate the following fields of the Registration page.
1. First Name (Name should contains alphabets and the length should not be less than 6
characters).
3. E-mail id (should not contain any invalid and must follow the standard pattern
DESCRIPTION: In order to validate the fields of login and registration pages JavaScript is
used. JavaScript is programming code that can be inserted into HTML pages. JavaScript
inserted into HTML pages, can be executed by all modern web browsers. JavaScript is
mainly used for validating the elements in a form submitted by the user. This JavaScript code
<html>
<body bgcolor="#E4F0F8">
<script type='text/javascript'>
function formValidator()
if(lengthRestriction(firstname, 6)){
if(lengthRestriction(pass, 6)){
if(lengthRestriction1(mobileno, 10 , 10)){
return true;
} } } }
}
}
} } }
return false;
if(elem.value.length == 0){
alert(helperMsg);
return false;
return true;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
return true;
}else{
elem.focus();
return false;
if(elem.value.match(emailExp))
return true;
else{
alert(helperMsg);
elem.focus();
return false;
return true;
else {
elem.focus();
return false;
</script>
</form>
</body>
</html>
WEEK - 3: Develop and demonstrate the usage of inline, internal and external style
Aim: Design a web page using CSS which includes the following:
PROGRAM:
style.css
p.left
text-align:left;
color:blue;
font-family:Cambria;
font-size:large;
text-indent:20px;
}
p.center
text-align:center;
text-decoration:underline;
text-transform:uppercase;
letter-spacing:-3px;
word-spacing:20px;
font-size:larger;
p.right
text-align:right;
color:red;
font-family:Tahoma;
font-size:15pt;
text-decoration:overline;
font-style:italic;
b#headline
color:orange;
font-size:22px;
font-family:arial;
text-decoration:underline;
<html>
<head>
<style type="text/css">
body
{
background-image:url('images/cse.png');
background-repeat:no-repeat;
background-position:center center;
background-attachment:fixed;
background-color:pink;
a:link { text-decoration:none;color:orange; }
a:visited { text-decoration:none;color:red; }
a:hover { text-decoration:underline;color:blue; }
a:active { text-decoration:underline;color:purple; }
h3 { color:green; }
.c1{cursor:crosshair}
.c2{cursor:pointer}
.c3{cursor:move}
.c4{cursor:text}
.c5{cursor:wait}
.c6{cursor:help}
</style>
</head>
<body bgcolor="cyan">
</html>
Output:
WEEK - 4: Develop and demonstrate JavaScript with POP-UP boxes and functions for
d) Input: A number n obtained using prompt and add another number using confirm
PROGRAM:
a) date.html
<html>
<body>
<script>
function display(){
var date=d.getDate();
var month=d.getMonth();
month++;
var year=d.getFullYear();
document.getElementById("dis").value=date+"/"+month+"/"+year;
</script>
<form>
</form>
<body>
</html>
OUTPUT:
b) factorial.html
<html>
<head>
<title>factorial</title>
<script language='javascript'>
function factorialcalc()
factorial = 1
factorial = factorial * i
</script>
</head>
<body><form name=frm>
</form>
</body>
</html>
c) multable.html
<html>
<body>
<script type="text/javascript">
<!--
if(!isNaN(n)) {
var table="";
var number="";
for(i=1;i<=10;i++) {
number = n * i;
alert(table);
else {
// -->
</script>
</body>
</html>
OUTPUT:
d) sum of n numbers.html
<html>
<script language='javascript'>
function addsum()
alert("you're going to give me a list of numbers. i'm going to add them together for you");
while (keepgoing) {
</script>
</head>
<body>
<form name=frm>
</form>
</body>
</html>
OUTPUT:
WEEK - 5:
Write an HTML page that contains a selection box with a list of 5 countries. When the
user selects a country, its capital should be printed next in the list. Add CSS to
customize the properties of the font of the capital (color,bold and font size).
<html>
<head>
</head>
<style>
h1
color: red;
text-align: center;
.textbox1
color: blue;
font-size: 30px;
font-weight: bold;
</style>
<body>
<center>
<form name="myform">
<option value=""></option>
<option value="CANBERRA">AUSTRALIA</option>
<option value="LONDON">UNITEDKINGDOM</option>
<option value="BERLIN">GERMANY</option>
</select><br><br>
Capital <input type="text" class="textbox1" id="sbox2">
</form>
</center>
<script>
function myFunction()
{ var a=document.getElementById("sbox1").value;
document.getElementById("sbox2").value=a; }
Week - 6:
Write an HTML page including any required JavaScript that takes a number from text
field in the range of 0 to 999 and shows it in words. It should not accept four and above
PROGRAM:
0-999.html
<html>
<head>
<SCRIPT language=Javascript>
<!--
function isNumberKey(evt)
return false;
return true;
//-->
</SCRIPT>
<script>
var once = ['Zero', ' One', ' Two', ' Three', ' Four', ' Five', ' Six', ' Seven', ' Eight', ' Nine'];
var twos = ['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', '
var tens = ['', 'Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', '
Ninety'];
numLength = rev.length;
var j = 0;
switch (i) {
case 0:
word[j] = '';
else {
word[j] = once[rev[i]];
word[j] = word[j];
break;
case 1:
aboveTens();
break;
case 2:
if (rev[i] == 0) {
word[j] = '';
else {
break;
default: break;
j++;
function aboveTens() {
word.reverse();
document.getElementById(outputControl).innerHTML = finalOutput;
</script>
</head>
<body>
</div>
</body>
</html>
OUTPUT:
WEEK - 7: Develop and demonstrate PHP Script for the following problems:
a) Write a PHP Script to find out the Sum of the Individual Digits.
b) Write a PHP Script to check whether the given number is Palindrome or not
<?php
$n=323;
$sum=0;
while($n>0)
$r=$n%10;
$sum+=$r;
$n=$n/10;
?>
Output:
<?php
$n=323;
$t=$n;
$rev=0;
while($n>0)
$r=$n%10;
$rev=$rev*10+$r;
$n=(int)($n/10);
if($t==$rev)
else
?>
Output:
Week - 8:
Create an XML document that contains 10 users information. Write a Java Program,
which takes User Id as input and returns the user details by taking the user information
AIM: Takes User Id as input and returns the user details using XML with DOM
PROGRAM:
users.xml
<usersinformation>
<user>
<rollno>501</rollno>
<name>aaa</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>502</rollno>
<name>bbb</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>503</rollno>
<name>ccc</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>504</rollno>
<name>ddd</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>505</rollno>
<name>eee</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>506</rollno>
<name>fff</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>507</rollno>
<name>ggg</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>508</rollno>
<name>hhh</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>509</rollno>
<name>iii</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
<user>
<rollno>510</rollno>
<name>jjj</name>
<branch>cse</branch>
<college>mrcet</college>
</user>
</usersinformation>
UserDom.java
import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.util.Scanner;
DocumentBuilderFactory fac=DocumentBuilderFactory.newInstance();
DocumentBuilder b=fac.newDocumentBuilder();
Element root=doc.getDocumentElement();
int n=in.nextInt();
int flag=0;
NodeList nl=doc.getElementsByTagName("user");
for(int i=0;i<nl.getLength();i++)
Node node=nl.item(i);
if(node.getNodeType()==Node.ELEMENT_NODE)
Element e=(Element)node;
int
x=Integer.parseInt(e. getElementsByTagName("rollno").item(0).getTextContent());
if(x==n)
System.out.println(root.getNodeName());
System.out.println("--------------------------------");
System.out.println("rollno:\t"+e.getElementsByTagName("rollno").item(0).getTextContent());
System.out.println("name:\t"+e.getElementsByTagName("name").item(0).getTextContent());
System.out.println("branch:\t"+e.getElementsByTagName("branch").item(0).getTextContent());
System.out.println("college:"+e.getElementsByTagName("college").item(0).getTextContent());
flag=1;
break;
else
flag=0;
}
}
if(flag==0)
OUTPUT:
WEEK - 9:
Implement the following web applications using (a) PHP, (b) Servlets and (c) JSP.
9 (i) (a). A web application that takes a name as input and on submit it shows a hello
<name> page where name is taken from the request. It shows the start time at the right
top corner of the page and provides a logout button. On clicking this button, it should
show a logout page with Thank You <name > message with the duration of usage (hint:
PROGRAM:
login.html
<html>
</html>
Output of login.html:
Home.php:
<?php
session_start();
date_default_timezone_set("Asia/Calcutta");
$_SESSION['luser'] = $_POST['text1'];
$_SESSION['start'] = time();
$tm=$_SESSION['start'];
print "</form>";
?>
Logoutpage.php:
<?php
session_start();
date_default_timezone_set("Asia/Calcutta");
session_destroy();
?>
Output of Logoutpage.php
9 (ii) (a). Write a PHP Program to display current Date, Time and Day using PHP
Script.
PROGRAM:
date.php
<?php
date_default_timezone_set ("Asia/Calcutta");
echo date("d/m/y");
$day=date("l");
echo $day;
?>
Output:
9 (iii) (a). A web application 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
the site” message, where <name> should be replaced with the entered name. Otherwise
AIM: To design an application to validate age are less than 18 or more than 18 using PHP.
PROGRAM:
checkage.html
<html>
<body bgcolor="bisque">
<input type='submit'value='Login'>
</form>
</body>
</html>
home.php
<?php
$name = $_POST['name'];
$age = $_POST['age'];
print "Hello " . $name . " you are not authorized to visit this site.";
else
?>
Output:
9 (iv) (a). A web application that lists all cookies stored in the browser on clicking “List
PROGRAM:
cookieset.php
<html>
<center>
<?php
$firstname = 'aaa';
$middlename = 'bbb';
$lastname = 'ccc';
setcookie('first_name',$firstname,time() + 86400);
setcookie('middle_name',$middlename,time() + 86400);
setcookie('last_name',$lastname,time() + 86400);
?>
</center>
</body>
</html>
Output:
ListCookie.php
<html>
<body bgcolor="GreenYellow">
<center>
</form>
</center>
<?php
error_reporting(0);
if($_POST['list'])
foreach($_COOKIE as $key=>$val)
?>
</body>
</html>
Output:
9 (i) (b). A web application that takes a name as input and on submit it shows a hello
<name> page where name is taken from the request. It shows the start time at the right
top corner of the page and provides a logout button. On clicking this button, it should
show a logout page with Thank You <name > message with the duration of usage (hint:
USING SERVLET
Session1.html
<html>
<body>
<center>
</form>
</center>
</body>
</html>
Session1.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
ServletException
try
res.setContentType("text/html");
PrintWriter out=res.getWriter();
String un=req.getParameter("uname");
HttpSession session=req.getSession();
session.setAttribute("user",un);
session.setAttribute("time",d.getTime());
out.println("Hello\t"+un);
out.println("</form");
}
catch(Exception e)
e.printStackTrace();
} }
Session2.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
ServletException
try
res.setContentType("text/html");
PrintWriter out=res.getWriter();
HttpSession session=req.getSession();
String un=(String)session.getAttribute("user");
Long t1=(Long)session.getAttribute("time");
Long t2=d2.getTime();
session.invalidate();
out.println("Thank you\t"+un);
catch(Exception e)
e.printStackTrace();
}
web.xml
<?xml version="1.0"?>
<web-app>
<servlet>
<servlet-name>session1</servlet-name>
<servlet-class>Session1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>session1</servlet-name>
<url-pattern>/session6vib</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>session2</servlet-name>
<servlet-class>Session2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>session2</servlet-name>
<url-pattern>/session26vib</url-pattern>
</servlet-mapping>
</web-app>
Aim: To print Current date and time using Servlet.
USING SERVLET
DateSrv.java
import java.io.*;
import javax.servlet.*;
//implement service()
ServletException
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.close();
web.xml
<?xml version="1.0"?>
<web-app>
<servlet>
<servlet-name>Date</servlet-name>
<servlet-class>DateSrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Date</servlet-name>
<url-pattern>/date</url-pattern>
</servlet-mapping>
</web-app>
Output:
9 (iii) (b). A web application 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
the site” message, where <name> should be replaced with the entered name. Otherwise
AIM: To design an application to validate age are less than 18 or more than 18 using SERVLET.
USING SERVLET
index.html:
<html
<head>
<title>VoterApp</title>
</head>
<body>
<table>
<tr><td></td>
</table>
</fieldset>
</form>
</body>
</html>
VoterSrv.java:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
IOException,ServletException
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
if (age>=18)
else
pw.println("<font color='red' size='4'>Hello "+name+", you are not authorized tovisit the
site</font>");
pw.close();
}
}
web.xml:
<web-app>
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>VoterSrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>abc</servlet-name>
<url-pattern>/check</url-pattern>
</servlet-mapping>
</web-app>
Output:
9 (iv) (b). A web application that lists all cookies stored in the browser on clicking “List
Cookies” button. Add cookies if necessary.
USING SERVLET
index.html
<html>
<head>
<title>CookiesExample</title>
</head>
<body>
</form>
</fieldset>
</form>
</body>
</html>
MyServlet1.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
try{
response.setContentType("text/html");
response.addCookie(c1);
response.addCookie(c2);
pwriter.close();
}catch(Exception exp){
System.out.println(exp);
MyServlet2.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
HttpServletResponse response){
try{
response.setContentType("text/html");
//Reading cookies
Cookie c[]=request.getCookies();
for(int i=0;i<c.length;i++){
pwriter.print("<br>"+c[i].getName()+": "+c[i].getValue());//printing name and value of
cookie
pwriter.close();
}catch(Exception exp){
System.out.println(exp);
web.xml
<web-app>
<display-name>Cookies Example</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>MyServlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Servlet2</servlet-name>
<servlet-class>MyServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
9 (i) (c). A web application that takes a name as input and on submit it shows a hello
<name> page where name is taken from the request. It shows the start time at the right
top corner of the page and provides a logout button. On clicking this button, it should
show a logout page with Thank You <name > message with the duration of usage
USING JSP
Sessionjsp.html
<html>
<body>
<center>
<form action="http://localhost:8080/jsp/Session1.jsp" method="get">
</form>
</center>
</body>
</html>
Session1.jsp
<%
%>
<%
String un=request.getParameter("uname");
session.setAttribute("user",un);
session.setAttribute("time",d.getTime());
%>
Hello <%=un%>
<br><br>
</form>
Session2.jsp
<%
String un=(String)session.getAttribute("user");
Long t1=(Long)session.getAttribute("time");
Long t2=d2.getTime();
%>
Thank you <%=un%>
<br><br>
<% session.invalidate();%>
9 (ii) (b). Write a JSP application to print the current date and time.
test.jsp
<html>
<head><title>JSPApp</title></head>
<body>
<form>
<legend><b><i>JSP Application<i><b></legend>
out.println(d.toString()); %>
</fieldset>
</form>
</body>
</html>
Output:
9 (iii) (c). A web application 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
the site” message, where <name> should be replaced with the entered name. Otherwise
it should send “Welcome <name> to this site” message.
AIM: To design an application to validate age are less than 18 or more than 18 using JSP.
USING JSP
UserEligibility.html:
<html>
<body> <br>
<center>
</form>
</center>
</body>
</html>
checkage.jsp:
<%
String name;
int age;
name=request.getParameter("uname");
age=Integer.parseInt(request.getParameter("uage"));
if(age<=18)
else
%>
9 (iv) (c). A web application that lists all cookies stored in the browser on clicking “List
USING JSP
cookie.html
<html>
<body>
</form>
</center>
</body>
</html>
cookie1.jsp
<%@page language="java" import="java.sql.*" errorPage=""%>
<%
String name=request.getParameter("name1");
response.addCookie(c1);
c1.setMaxAge(50*50);
%>
</form>
cookie2.jsp
<%
Cookie[] cookies=request.getCookies();
%>
<table border=1>
</tr>
<%
for(int i=0;i<cookies.length;i++)
"+cookies[i].getName()+"</td><td>"+cookies[i].getValue()+"</td></tr>");
%>
</tr>
</table>
WEEK - 10: Implement the web applications with Database using
a) A user validation web application, where the user submits the login name &
password to the server. The name and password are checked against the data already
available in Database and if the data matches, a successful login page is returned.
PROGRAM:
db.php
<html>
<body>
<?php
$severname="localhost";
$username="root";
$password="TIGER";
$conn=new mysqli($severname,$username,$password);
if($conn->connect_error)
die("connection failed".$conn->connect_error);
//Create database
if(mysqli_query($conn,$sql))
else
echo "error";
$servername="localhost";
$dbname="reg";
// Check connection
if (!$conn)
if (mysqli_query($conn, $sql))
else {
if (mysqli_query($conn, $sql)) {
else
mysqli_close($conn);
?>
</body>
</html>
Output of db.php:
Login.html
<html>
<body>
<table>
</tr>
</tr>
</tr>
</table>
</form>
</center>
</body>
</html>
loginform.php
<html>
<body>
<?php
$name=$_POST["uname"];
$pwd=$_POST["upwd"];
$conn=mysql_connect("localhost","root","TIGER") or die("mysql_error()");
mysql_select_db("reg") or die("mysql_error()");
while($row=mysql_fetch_array($query))
$duser=$row['name'];
$dpwd=$row['pwd'];
else
?>
</body>
</html>
OUTPUT:
(b) USING SERVLET
DBExample.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
HttpServletResponse response)
String JDBC_DRIVER="com.mysql.jdbc.Driver";
String DB_URL="jdbc:mysql://localhost/csec";
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body><h1>Welcome to MRCET</h1>\n") ;
try{
Class.forName("com.mysql.jdbc.Driver");
USER, PASS);
String sql;
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
rs.close();
stmt.close();
conn.close();
}catch(SQLException se){
out.println(se.getMessage());
}catch(Exception e){
out.println(e.getMessage());
out.println("</body></html>");
<web-app>
<servlet>
<servlet-name>DBExample</servlet-name>
<servlet-class>DBExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DBExample</servlet-name>
<url-pattern>/db</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
import java.sql.*;
class MysqlCon{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","root");
Statement stmt=con.createStatement();
con.close();
OUTPUT:
WEEK - 11:
AIM: To design an application that verifies user details from an xml using PHP.
PROGRAM:
db.php
Userlogin.xml:
<Authentication>
<user>
<username>cse</username>
<password>5</password>
</user>
<user>
<username>mrcet</username>
<password>mlrd</password>
</user>
</Authentication>
Loginform.php:
<html>
<head>
</head>
<body bgcolor="pink">
<?php
$myxml=simplexml_load_file("Userlogin.xml");
$username=$_POST['uname'];
$password=$_POST['upwd'];
$xmlusername="";
$xmlpassword="";
for($i=0;$i<count($myxml);$i++)
$xmlusername=$myxml->user[$i]->username;
$xmlpassword=$myxml->user[$i]->password;
die();
?>
</body>
</html>
Loginform.php:
<html>
<head> <title> Login Page </title> </head>
<body bgcolor="bisque">
<center>
<table>
</tr>
</tr>
</td>
</tr>
WEEK - 12:
Write a program to design a simple calculator using (a) JavaScript (b) PHP (c) Servlet
PROGRAM:
cal.html
<html>
<head>
<title>Calculator</title>
<script language="javascript">
var inputstring="";
function updatestring(value)
inputstring=inputstring+value;
document.calculator.input.value=inputstring;
</script>
</head>
<body>
<form name="calculator">
<tr>
<tr>
<tr>
<tr>
PROGRAM:
form.html
<html>
</form>
</body>
</html>
add.php
<?php
$a = $_POST['t1'];
$b = $_POST['t2'];
if (isset($_POST['add']))
$c = $a + $b;
if (isset($_POST['sub']))
$c = $a - $b;
if (isset($_POST['mul']))
{
$c = $a * $b;
if (isset($_POST['div']))
$c = $a / $b;
?>
(c) USING SERVLETS
and ServletOutputStream.
DESCRIPTION:
In java with using 2 operant’s and 1 operator we can calculate the basic mathematically
operation such as addition, subtraction, multiplication, division Servlet is a Java class which
extends the capabilities of server that provides the application accessed by means of request
HTTPRequest: This is an interface which provides methods for extracting HTTP parameters
from the query or request body depending on the type of request i.e. get or post
PROGRAM:
index.html
<html>
<head>
<title>Simple Calculator</title>
</head>
<body>
<select name="op">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="%">%</option>
</select></br>
</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;
response.setContentType("text/html;charset=UTF-8");
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{pw.println("Remainder :::"+(n1%n2));}
pw.close();
}}
web.xml
<web-app>
<servlet>
<servlet-name>Calculator</servlet-name>
<servlet-class>Cal</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Calculator</servlet-name>
<url-pattern>/calc</url-pattern>
</servlet-mapping>
</web-app>
Output:
calculator.html
<html>
<title>calculator</title>
<head><h1><center>Basic Calculator</center></h1></head>
<body>
<center>
</center>
</body>
</html>
calculator.jsp
<html>
<title>calculator</title>
<head></head>
<body>
<%@page language="java"%>
<%
if(operation.equals("Add")){
int add=num1+num2;
else if(operation.equals("Sub")){
int sub=num1-num2;
else if(operation.equals("mul")){
int mul=num1*num2;
out.println("multiplication is: "+mul);
else if(operation.equals("div"))
if(num1>=num2)
else
%>
</body>
</html>
OUTPUT: