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
ManishLeadAsked:
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.

rrzCommented:
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();
  conn.setConnectTimeout(100);
  conn.connect();
  out.print("Response code is " + conn.getResponseCode());
%>

Open in new window

0
ManishLeadAuthor Commented:
No I want it in jstl.
0
rrzCommented:
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  
http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html#bnaiq

package testing;
import java.net.*;
import java.io.*;
public class Functions {
    public static String conTime(String urlString) {
          try{
              URL url = new URL(urlString);
              HttpURLConnection conn = (HttpURLConnection)url.openConnection();
              conn.setConnectTimeout(100);
              conn.connect();
              return  "Response code is " + conn.getResponseCode();
          }catch(Exception ioe){return ioe.toString();}
    }
}       
--------------------------------------------------------------
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
  version="2.0">
  <tlib-version>1.0</tlib-version>
  <short-name>Functions</short-name>
  <uri>http://tester.com</uri>
<function>
    <name>conTime</name>
    <function-class>testing.Functions</function-class>
    <function-signature>
        java.lang.String conTime(java.lang.String)
    </function-signature>
</function>
</taglib>
-----------------------------------------------------------------
<%@ 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

0

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.
0
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.