<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # JSP 中的`exception`隱式對象 > 原文: [https://beginnersbook.com/2013/11/jsp-implicit-object-exception-with-examples/](https://beginnersbook.com/2013/11/jsp-implicit-object-exception-with-examples/) 在本教程中,我們將討論 JSP 的`exception`隱式對象。它是`java.lang.Throwable`的一個實例,經常用于 JSP 中的異常處理。此對象僅適用于錯誤頁面,這意味著 JSP 頁面的`isErrorPage`應為`true`,以便使用`exception`隱式對象。讓我們在下面的例子的幫助下理解這一點: ### `exception`隱式對象示例 在這個例子中,我們從用戶那里獲取兩個整數輸入,然后我們在它們之間進行劃分。我們在下面的例子中使用了`exception`隱式對象來處理任何類型的異常。 `index.html` ```html <html> <head> <title>Enter two Integers for Division</title> </head> <body> <form action="division.jsp"> Input First Integer:<input type="text" name="firstnum" /> Input Second Integer:<input type="text" name="secondnum" /> <input type="submit" value="Get Results"/> </form> </body> </html> ``` 這里我們將`exception.jsp`指定為`errorPage`,這意味著如果在此 JSP 頁面中發生任何異常,控件將立即轉移到`exception.jsp` JSP 頁面。注意:我們使用了`page`指令的`errorPage`屬性來指定異常處理 JSP 頁面(`<%@ page errorPage="exception.jsp" %>`)。 `division.jsp` ```html <%@ page errorPage="exception.jsp" %> <% String num1=request.getParameter("firstnum"); String num2=request.getParameter("secondnum"); int v1= Integer.parseInt(num1); int v2= Integer.parseInt(num2); int res= v1/v2; out.print("Output is: "+ res); %> ``` 在下面的 JSP 頁面中,我們將`isErrorPage`設置為`true`,它也是`page`指令的一個屬性,用于使頁面有資格進行異常處理。由于此頁面在`division.jsp`中定義為異常頁面,因此在任何異常情況下都將調用此頁面。這里我們使用`exception`隱式對象向用戶顯示錯誤消息。 `exception.jsp` ```html <%@ page isErrorPage="true" %> Got this Exception: <%= exception %> Please correct the input data. ``` **輸出** 屏幕,帶有兩個輸入字段,用于兩個整數。 ![inputPage](https://img.kancloud.cn/8e/70/8e70f3b0744030787e9c98b1108d2739_626x322.jpg) 當我們提供第二個整數為零時的算術異常消息。 ![exceptionPage](https://img.kancloud.cn/ba/bb/babb6ed5673597b107d44b6a9e8b9390_626x322.jpg) 如果您對 JSP 中的`exception`隱式對象有任何疑問,請告訴我們。這是在 JSP 中構建應用時最常用的隱式對象之一。作為替代方案,您還可以通過在 JSP scriptlet 中使用`try catch`來處理 JSP 中的異常。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看