日期:2014-05-17  浏览次数:20711 次

JSTL异常属性问题
XML code

<%@  taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page errorPage="errorPage.jsp"    %>
<html>
    <body>
        About to be do a risky thing:    <br/>
        
        <c:catch var="myException">
            Inside  the catch...        <br/>
            <% int x = 10/0; %>
            <% out.println(x); %>
        </c:catch>
        
        <c:if test=" ${myException != null } ">
            There was an exception : ${ myException.message }    <br/>
        </c:if>
        
        If you see this, we survived.
        
    </body>
</html>




为什么不能打印 There was ... ?
谢谢

------解决方案--------------------
不能打印就是myException 为空了。。。。。
------解决方案--------------------
<c:if test="${myException != null}">
There was an exception : ${ myException.message } <br/>
</c:if>


test="${myException != null}"
把这里面的空格都去掉
------解决方案--------------------
我表示很担心楼主的这行代码:<% int x = 10/0; %>

用10除以0 有意义吗?
------解决方案--------------------
test=" ${myException != null}"


" 和$之间不能有空格,也就是说test=" true" 这样带空格的值,是不对的

应该为test="true"才对,我试过了,改了之后已经可以打印There was ... 了