<html>
<title>Sample Example </title>
<body>
<form method="post" action="index.jsp">
<fieldset style="width:30%; background-color:#b3d1ff">
<h2><center> Mathematical Operation</center></h2>
<hr>
<font size=5 face="Times New Roman">
<input type="radio" name="a1" value="add" checked>Addition</input><br>
<input type="radio" name="a1" value="sub">Subtraction</input><br>
<input type="radio" name="a1" value="mul" >Multiplication</input><br>
<input type="radio" name="a1" value="div" >Division</input><br>
</font>
<table>
<tr>
<td>Enter first Value:</td>
<td> <input type="text" name="t1" value=""></td>
</tr>
<tr>
<td>Enter second Value: </td>
<td><input type="text" name="t2" value=""></td>
</tr><br>
<tr>
<td></td>
<td><input type="submit" name="result" value="Check result!"></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
<%@ page errorPage="error.jsp" %>
<html>
<body>
<H1><center>Result for <%=request.getParameter("a1")%></center></H1>
<%
String num1=request.getParameter("t1");
String num2=request.getParameter("t2");
int i=Integer.parseInt(num1);
int j=Integer.parseInt(num2);
int k=0;
String str=request.getParameter("a1");
if(str.equals("add"))
k=i+j;
if(str.equals("sub"))
k=i-j;
if(str.equals("mul"))
k=i*j;
if(str.equals("div"))
k=i/j;
%>
Result is: <%=k%>
</body>
</html>
<%@ page isErrorPage="true" %>
<h3>Sorry an exception occured!</h3>
Exception is: <%= exception %>
<web-app>
<servlet>
<servlet-name>xyz</servlet-name>
<jsp-file>/input.html</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>xyz</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>