C: import or c: url - specify a timeout value

I would like to use c: import or c: url to capture the contents of a page (ad server). In addition, I need to specify a timeout, and if the call or timeout or page is not available, I need the default text, which will be returned as my value.

Is there a jstl tag lib for this? Or do I need to create my own?

+4
source share
1 answer

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.

+4
source

All Articles