JSP JSTL ( jstl-1.2.jar /WEB-INF/lib) <c:import> <c:catch> . <c:import> IOException (FileNotFoundException), . <c:catch> Throwable . <c:choose> ( <c:if>) .
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="url" value="http://google.com" />
<c:catch var="e">
<c:import url="${url}" var="ignore"></c:import>
</c:catch>
<c:choose>
<c:when test="${not empty e}">
<p>Site doesn't exist
</c:when>
<c:otherwise>
<c:redirect url="${url}" />
</c:otherwise>
</c:choose>
var="ignore" , JSP.
, JSP . HttpServlet Filter JSP, , . JSP - . a HttpServlet :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url = "http://google.com";
try {
new URL(url).openStream();
response.sendRedirect(url);
} catch (IOException e) {
throw new ServletException("URL " + url + " does not exist", e);
}
}