<C: captura> tag
<C: captura> tag é usado principalmente para tratar condições anormais que produziu o erro, ea mensagem de erro é armazenado.
sintaxe
<c:catch var="<string>"> ... </c:catch>
propriedade
<C: captura> tag tem os seguintes atributos:
propriedade | descrição | Se necessário | omissão |
---|---|---|---|
var | As variáveis usadas para armazenar a mensagem de erro | não | nenhum |
Exemplos Demonstração
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>c:catch 标签实例</title> </head> <body> <c:catch var ="catchException"> <% int x = 5/0;%> </c:catch> <c:if test = "${catchException != null}"> <p>异常为 : ${catchException} <br /> 发生了异常: ${catchException.message}</p> </c:if> </body> </html>
Exemplos dos resultados operacionais acima:
异常为 : java.lang.ArithmeticException: / by zero 发生了异常: / by zero