java.net.ProtocolException:设置CookieHandler时不';行不通

java.net.ProtocolException:设置CookieHandler时不';行不通,java,jsp,Java,Jsp,以下是我在jsp中的代码: <c:catch var="feederror"> <% String feedUrl = (String) pageContext.getAttribute("url"); String feedXml = ""; HttpURLConnection conn = (HttpURLConnection) new URL(feedUrl).openConnection(); Buff

以下是我在jsp中的代码:

<c:catch var="feederror">
    <%
        String feedUrl = (String) pageContext.getAttribute("url");
        String feedXml = "";  
      HttpURLConnection conn = (HttpURLConnection) new URL(feedUrl).openConnection();
      BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      String line;
      while ((line = reader.readLine()) != null) {
          feedXml += line;
      }
      reader.close();
      pageContext.setAttribute("feedXml", feedXml.trim().replaceAll("",""));    
    %>
</c:catch>

变量feederror返回java.net.ProtocolException:服务器重新检测次数过多(20)

我试过:

  • 用禁用的cookie打开浏览器-页面根本不加载(404)
  • 在打开连接之前使用了CookieHandler.setDefault(新CookieManager(null,CookiePolicy.ACCEPT_ALL))-未更改任何内容
  • 已尝试CookieHandler.setDefault(new CookieManager())-未更改任何内容

如何解决该问题?

java.net.ProtocolException:服务器重新检测的次数太多(20次)

此异常来自HttpURLConnection conn=(HttpURLConnection)新URL(feedUrl).openConnection()

99%的情况下,你调用的是一个url,它发送一个重定向到自身,或者是站点B,它重定向到站点a,它重定向到站点B等等。所以有一个循环

检查您试图调用的URL并通过一些外部工具进行验证,这样您就可以检查来自外部服务器的标题和响应


我认为这与Cookie无关

@Shafinamhmud,以前读过并尝试过“维护会话”部分。“服务器重定向太多次”的哪个部分你不明白吗?@EJP我不知道如何解决这个问题