Professional Documents
Culture Documents
Experiment 3.2
Student Name: Iesh Bajetha UID:21BCS5556
Branch: B.E.-CSE Section/Group: 21BCS-FL-602B
Semester: VI Date of Performance: 26/03/2024
Subject Name: Java Lab Subject Code: 21CSH-319
1. Aim:
Create JSP application for addition, multiplication and division.
2. Objective:
• To learn about JSP (Java Server Page.
• To learn about various JSP tags.
3. Code:
a) index.jsp
<%@ page errorPage="error.jsp" language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<style type='text/css'>
div {
padding:10px;
border:2px outset black;
background-color: lightblue;
width:450px;
}
</style>
</head>
<body>
<div>
<h1 align="center">Mathematical Operation</h1>
<hr>
</body>
</html>
b) process.jsp
<%@ page errorPage="error.jsp" language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Result</title>
</head>
<body>
<h2>Result</h2>
<%!
double add(double num1, double num2) {
return num1 + num2;
}
c) error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isErrorPage="true"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Error</title>
</head>
<body>
<h3>Sorry an exception occured!</h3>
Exception is: <%= exception %>
</body>
</html>
d) web.xml
<?xml version="1.0" encoding="UTF-8"?>
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
<web-app>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
</web-app>
4. Output:
5. Leaning Outcome: