English 中文(简体)
Java Struts——死链路核对器
原标题:Java Struts - Dead Link Checker

我需要检查一套内联网网站。 我试图使用以下法典。 (通过在互联网上的随机搜索而查阅这一法典)。 我将这种方法称为我的行动类别。 但大多数进入例外部分的地点。 尽管我能够从我的浏览器上开放这些场所,但我还是获得了《议定书》的例外和<代码>。

参考守则:

public boolean isLive(String link) {  
  HttpURLConnection urlConnection = null;  
  try {  
    URL url = new URL(link);  
    urlConnection = (HttpURLConnection) url.openConnection();  
    urlConnection.setRequestMethod("HEAD");  
    urlConnection.setConnectTimeout(5000); /* timeout after 5s if can t connect */  
    urlConnection.setReadTimeout(5000); /* timeout after 5s if the page is too slow */  
    urlConnection.connect();  
    String redirectLink = urlConnection.getHeaderField("Location");  
    if (redirectLink != null && !link.equals(redirectLink)) {  
      return isLive(redirectLink);  
    } else {  
      return urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK;  
    }  
  } catch (Exception e) {  
    return false;  
  } finally {  
    if (urlConnection != null) {  
      urlConnection.disconnect();  
    }  
  }  
}  
问题回答

I think No Problem with the code. You have a connection timeout of 5 seconds

urlConnection.setConnectTimeout(5000)   

Any query that takes more than 5 seconds will be considered a dead link.Your Browser have much longer timeout than your code so you are able to browse those sites in the browser

如果你重新获得礼宾例外和未知的东道国例外,我们就需要更多了解才能提供帮助。 您的机器是否配置成代理? 您是否有东道方定义,由您的集装箱用户共享?

此外,还考虑使用HttpClient等内容来总结这方面的情况,而不是以人工方式进行;工作太多。





相关问题
Struts 1.2.9 Action Chaining

I m having trouble calling a method in one Struts action from a method in another Struts Action (I ve been told that this is possible). I m working with two Struts DynaValidatorForms - one is used to ...

Java Struts Report

I am writing an excel report using an action,controller, servlet struts framework. The report is very congested and has already around 10 separate queries. I need to add about 10 more queries due to a ...

Struts Tiles 1 - nested tiles issue

I am using Struts tiles 1 succesfully, however I have come across a problem when trying to nest tiles. I currently have a layout like so: I wish to have another template like this, for use in quite ...

array as hidden variable

can array be used as hidden variable on jsp.....like I have a form i.e a simple java class,I want it to be as hidden variable can I do it.. Thanks in advance

GZIP JSON AJAX response text is empty

I am facing a problem, while encoding the response that I send back for an AJAX request, using GZIP. Can anyone give me some pointers on this please? There is an AJAX request from the JSP, An action ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签