zoukankan      html  css  js  c++  java
  • JSP应用程序(自定义错误页面)

    一、编写

    1、index.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <form action="login.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="name"/></td>
                        </tr>
                        <tr>
                            <td>enter password:</td>
                            <td><input type="text" name="password"/></td>
                        </tr>
                    </table>
                    <table align="center">
                        <tr>
                            <td><input type="submit" value="login" /></td>
                            <td><input type="reset" value="cancel" /></td>
                        </tr>
                    </table>
                </font>
            </form>
        </body>
    </html>

    2、login.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    
    <%@ page errorPage="error.jsp" %><!--添加-->
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <%
                String user=request.getParameter("name");
                String password=request.getParameter("password");
                int p=Integer.parseInt(password);
                if(user.equals("John")&& p==123){
                    out.println("Welcome to online banking system");
                    out.println("   login successful");
                }
                else{
                    out.println("login unsuccessful");
                }
            %>
        </body>
    </html>

    3、error.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>An exception has occurred</h1>
            Exception Class:<%= pageContext.getException() %>
            <form action="index.jsp">
                <input type="submit" value="return" />
            </form>
        </body>
    </html>

    4、web.xml

      在</web-app>之前加入以下代码

    <error-page>
            <exception-type>java.lang.NumberFormatException</exception-type>
            <location>/error.jsp</location>
    </error-page>

    二、运行

  • 相关阅读:
    AndroidUI 控件命名格式
    VoIP常见编码的带宽计算
    Hessian 原理分析
    关于异步,同步,阻塞与非阻塞
    dubbo 官方参考手册~备案(防止哪天阿里一生气把dubbo给删除了)
    企业常用的RPC框架比较
    SpringMVC整合Hessian访问远程服务
    Hessian与Webservice的区别
    Dubbo与Zookeeper、Spring整合使用
    java.lang.ClassNotFoundException: org.I0Itec.zkclient.exception.ZkNoNodeException 异常 如何处理
  • 原文地址:https://www.cnblogs.com/shelly0307/p/3673401.html
Copyright © 2011-2022 走看看