<c:catch>-Tag
Das <c:catch>-Tag wird hauptsächlich verwendet, um Ausnahmen zu behandeln, die Fehler erzeugen, und die Fehlerinformationen zu speichern.
Syntaxformat
<c:catch var="<string>"> ... </c:catch>
Attribute
Das <c:catch>-Tag hat die folgenden Attribute:
| Attribute | Beschreibung | Erforderlich | Standardwert |
|---|---|---|---|
| var | Variable zum Speichern von Fehlerinformationen | nein | Keine |
Beispiel-Demonstration
<%@ 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>
Das Ergebnis der Ausführung des obigen Beispiels:
异常为 : java.lang.ArithmeticException: / by zero 发生了异常: / by zero
Andere Erweiterungen
JSP-Standard-Tag-Bibliothek