View.
c: import opens the socket for the server and simply returns what the connection is doing (raw html in your case). If the server returns page 404, then this is what will be displayed, 500, then you will get a page with an error.
Try this socket, then it has access to all socket errors. For timeout:
java.net.ConnectException: Operation timed out
Unknown host:
java.net.UnknownHostException: www.googasdasdasdassdle.com
This means that you can wrap your import in a catch statement and process it right on the page.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:catch var="socketExceptionVariable"> <c:import url="www.googasdasdasdassdle.com"/> </c:catch> <c:if test="${socketExceptionVariable != null}"> <p>There was an error here</p> <c:out value="${socketExceptionVariable}"/> </c:if>
If the import occurs, it works as intended, but if something (something) goes wrong, an error page is displayed.
You can write your own import tag, but it encapsulates it, but its fair bit of work compared to this solution.
source share