c import connect timeout

<c:import var="xmlFeed" url="anyurl"  charEncoding="iso-8859-1" /> is connecting to the URL specified. If the time taken to connect is more than 5 seconds then we want to disconnect? How to do it in JSTL? If not then how to set the connect timeout?
LVL 11
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't think we can do that in JSTL.  But here is code that works. Just change the value of the time period to test.   If you don't want to use a scriptlet, then we can put it into a tag file.
<%@ page import="java.net.*" %>
  URL url = new URL("http://www.google.com");
  HttpURLConnection conn = (HttpURLConnection)url.openConnection();
  out.print("Response code is " + conn.getResponseCode());

Open in new window

ManishLeadAuthor Commented:
No I want it in jstl.
It is easy to make a tag file.  But if you want to use JSTL, then you could define a custom EL function. Here is a class, tld, and a JSP that uses my custom function.   See  

package testing;
import java.net.*;
import java.io.*;
public class Functions {
    public static String conTime(String urlString) {
              URL url = new URL(urlString);
              HttpURLConnection conn = (HttpURLConnection)url.openConnection();
              return  "Response code is " + conn.getResponseCode();
          }catch(Exception ioe){return ioe.toString();}
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
        java.lang.String conTime(java.lang.String)
<%@ page import="java.net.*" %>
<%@taglib prefix="cto" uri="http://tester.com" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:out value="${cto:conTime('http://www.google.com')}"/>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ManishLeadAuthor Commented:
I was looking for something in c import tag.
ANyway Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.