Implementation of ERROR page in JSP
errorpage.jsp
<%@ page isErrorPage="true"%>
<%@ page import="java.io.*"%>
<html>
<head>
<title>Custom Error Page</title>
</head>
<body>
<h2>Your application has generated an error</h2>
<h3>Please check for the error given below</h3>
<b>Exception:</b><br>
<font color="red"><%= exception.toString()%></font>
</body>
</html>
errorexample.jsp
<HTML>
<HEAD>
<TITLE>
Login
</TITLE>
<%@ page language="java" contentType="text/html" %>
<%@page errorPage="errorpage.jsp"%>
</HEAD>
<BODY>
<FORM METHODE="post" ACTION="errorexample.jsp">
<CENTER>
<TABLE>
<TR>
<TD>Number1</TD>
<TD><input type="text" name="n1" id="n1"></TD>
</TR>
<TR>
<TD>Number2</TD>
<TD><input type="text" name="n2" id="n2"></TD>
</TR>
<TR>
<TD>Result</TD>
<TD><input type="text" name="n3" id="n3" value="<%
String num1=request.getParameter("n1");
String num2=request.getParameter("n2");
if((num1!=null)&&(num2!=null))
{
int nu1=Integer.parseInt(num1);
int nu2=Integer.parseInt(num2);
out.println(nu1/nu2);
}
%>">
</TD>
</TR>
<TR>
<TD></TD>
<TD><input type="submit" value="Divide"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<HEAD>
<TITLE>
Login
</TITLE>
<%@ page language="java" contentType="text/html" %>
<%@page errorPage="errorpage.jsp"%>
</HEAD>
<BODY>
<FORM METHODE="post" ACTION="errorexample.jsp">
<CENTER>
<TABLE>
<TR>
<TD>Number1</TD>
<TD><input type="text" name="n1" id="n1"></TD>
</TR>
<TR>
<TD>Number2</TD>
<TD><input type="text" name="n2" id="n2"></TD>
</TR>
<TR>
<TD>Result</TD>
<TD><input type="text" name="n3" id="n3" value="<%
String num1=request.getParameter("n1");
String num2=request.getParameter("n2");
if((num1!=null)&&(num2!=null))
{
int nu1=Integer.parseInt(num1);
int nu2=Integer.parseInt(num2);
out.println(nu1/nu2);
}
%>">
</TD>
</TR>
<TR>
<TD></TD>
<TD><input type="submit" value="Divide"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
OUTPUT
Jsp program to divide a number |
JSP error page |
No comments:
Post a Comment