2013-04-12 21 views
0

我在web.xml中使用了以下幾行,因此如果應用程序中出現GenericException,那麼可以調用genericException.jsp。如何將IF條件放在jsp中的<%= exception.getMessage()%>

<error-page> 
<exception-type>com.example.GenericException</exception-type> 
<location>/WEB-INF/jsp/genericException.jsp</location> 
</error-page> 

我想在我的屏幕上顯示exception.getMessage(),只有它是數字。 當我試圖使用$ {exception.getMessage()}在屏幕上打印它時,它不起作用

取而代之,我不得不使用<%= exception.getMessage()%>來打印相同的在屏幕上。

我只想打印相同的數字(錯誤代碼基本上)。
我的問題是,我無法檢查這是否是數字。有人可以告訴我,jsp中的邏輯將如何相同。

到目前爲止,我已經把IF條件對$ {exception.getMessage()}一種使用 C變量:如果測試=

但不能夠把IF條件對<%= exception.getMessage ()%>

+0

如果它是數字..你可以解釋一下嗎? –

+0

我編輯了我的問題。 – Shweta

+0

我想你的'com.example.GenericException'有類似'errorCode'屬性的東西,但是你應該把它的代碼作爲'如果它是數字'這個語句沒有任何意義,我們只會看到一個異常和一個異常是一個類,而不是一個數字。此外,你的JSP代碼的一小部分將有助於理解這個問題。 –

回答

0
<%@page import="com.example.GenericException"%> 
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true"%> 
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<html> 
<head><title>Error Message</title></head> 
<body> 
<form action="" method="post" > 

    <center> 
     <br><br> 
     <table width="90%" height="100px" 
       style=" -moz-border-radius: 8px; -webkit-border-radius: 8px;border-radius: 8px;border: 2px solid #467aa7;"> 
      <tr> 
       <td style="color:#467aa7;"> 
        <% 
         GenericException e = (GenericException) exception; 
         int code = e.getErrorCode(); 
         String message = e.getErrorMessage(); 

         if (code != 0) { 
          message = code + " : " + message; 
         } 
        %> 

        <label><%=message %></label> 
       </td> 
      </tr> 
     </table> 
    </center> 
</form> 
</body> 
</html> 
相關問題