SET AS HOME PAGE

ADD TO FAVORITES / BOOKMARK THIS WEBSITE (More Details)

Introduction

Servlet

Jsp

Security

Enterprise Beans

Contact Us


Simple JSP Example with ErrorPage

 Introduction

This example shows how to create a JSP project with ErrorPage. This example will show the type of error if the user inputed incorrectly

CLICK HERE to download this complete example (zip file)


 Steps to Create a JSP Application (JSP Program with ErrorPage)

You need to follow the following steps to create a JSP application:

  • Create a user interface using HTML
  • Create an Authentication Page using JSP
  • Create an Error Page using JSP
  • Package the user interface and JSP page:
  • Deploy the package you have created

Access the application using a Web browser:

 HTML file (main1.html)

<html>
<body>
<form name="f1" action="authenticate.jsp">
<font size=4 face="Verdana" color=#120292>
<marquee> Online Banking System </marquee>
<br><br>
<table cellspacing=5 cellpadding=5 bgcolor=#959999 colspan=2 rowspan=2 align="center">
<tr>
<td> Bank Customer Authentication Form</td>
</tr>
<tr>
<td>Enter Customer Id :</td>
<td><input type=text name="uname"></td>
</tr>
<tr>
<td>Enter Password: </td>
<td><input type=password name="password"></td>
</tr>
</table>
<br>
<table align="center">
<tr>
<td><input type="submit" value=" Login " ></td>
<td><input type="Reset" value=" Cancel " ></td>
</tr>
</table>
</font>
</form>
</body>
</html>
Download: main1.html

 JSP file (authenticate.jsp)

<%@ page errorPage="LoginErrorPage.jsp" %>
<html>
<body>
<font face ="verdana">
<%
String user=request.getParameter("uname");
int customerID=Integer.parseInt(user);
String pass=request.getParameter("password");
if( customerID== 1111 && pass.equals("Franklin"))
{
out.println("Welcome to Online Banking System");
%>
<br><br>
<%
out.println("Login Successful");
}
else
{
out.println("Login Unsuccessful");
}
%>
</font>
</body>
</html>
Download: authenticate.jsp

 JSP ErrorPage file (LoginErrorPage.jsp)

<%@ page isErrorPage="true" %>
<html>
<body>
<h3>An exception has occurred</h3>
<table>
<tr>
<td>Exception Class:</td>
<td><%= exception.getClass() %></td>
</tr>
<tr>
<td>Message:</td>
<td><%= exception.getMessage() %></td>
</tr>
</table>
<br>
To go to login page again, click Login Page button
<form name="f2" action="main.html">
<input type="submit" name="button1" value="Login Page">
</form>
</body>
</html>
Download: LoginErrorPage.jsp

 Steps to deploy and run this JSP Project

  1. Write a html file and name it as main1.html
  2. Write a jsp file and name it as authenticate.jsp
  3. Write a jsp error file and name it as LoginErrorPage.jsp
  4. Now goto Start -> Programs -> Sun Microsystems ->Application Server PE -> Start Default Server (wait till it start and then press any key). CLICK HERE to see how to Start the Server
  5. Next goto Start -> Programs -> Sun Microsystems ->Application Server PE -> Deploytool. CLICK HERE to see how to Start the Deploytool
    Now in the deploytool,
    1. Goto File ->New -> Application

      (Click the Browse button)


    2. (Select the folder in the Look In dropdown box, and then give a file name "Calculation". Next click the New Application button)


    3. (Click the OK button)
    4. Now goto File -> Save to save the file
    5. Next, goto File -> New -> Web Component

      (Click Next button)


    6. (Enter the WAR Name as "ErrApp" and then click the Edit Contents… button)


    7. (Select all the .class, .jsp , .tld and .html files and click the Add button)


    8. (Now click the OK button)


    9. (Now click the Next button)


    10. (Now select the JSP Page option button and then click the Next button)


    11. (Now select the "authenticate.jsp" from the Servlet Class dropdown box)


    12. (Now select the Next button)


    13. (Now select the Finish button)


    14. (Now select the ErrApp in the left pane and select the General tab in the right pane. Here give a name errorpage in the Context Root text box)
    15. Note: Here, no need Aliases name because the client HTML file directly calls the JSP file
    16. Now goto File ->Save
    17. Next goto Tools -> Deployee

      (Enter the User Name as “admin” and Password as “password” (CLICK HERE for password). Next click the OK button)


    18. (Now a message --- Operation Completed Successfully --- must display. Next click the Close button)
    19. Next goto File -> Exit to close it

 Click Next To Continue ...
<- PREVIOUSNEXT ->