【问题标题】:How to fix java.io.FileNotFoundException: Response: '404: Not Found' for url: 'http://localhost:7001/Socket-war/Servlet'如何修复 java.io.FileNotFoundException: 响应: '404: Not Found' for url: 'http://localhost:7001/Socket-war/Servlet'
【发布时间】:2014-06-22 13:40:21
【问题描述】:

我正在使用下面的代码从我的 Java 类中调用一个 servlet:

  URL url = new URL( "http://localhost:7001/Socket-war/Servlet" );
  new BufferedReader(new InputStreamReader(url.openStream()));  

获取异常:

java.io.FileNotFoundException: Response: '404: Not Found' for url: 'http://localhost:7001/Socket-war/Servlet'  

一切都很好;我以前也在我的其他程序中使用过它;但现在引发异常......

有人告诉我为什么?任何建议或建议都将是非常可观的。

谢谢!!!

【问题讨论】:

  • 您可以从浏览器访问 servlet 吗?
  • 是的,我可以使用浏览器。
  • 你可以试试 127.0.0.1 代替 localhost 吗?
  • 另外,您的网络中是否有任何代理设置?
  • 再次获取异常:java.io.FileNotFoundException:响应:'404: Not Found' for url:'127.0.0.1:7001/Socket-war/Servlet' at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:568 ) 在 weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:568) 在 weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:37) 在 java.net.URL.openStream(URL.java:1037)

标签: java url filenotfoundexception inputstreamreader buffered


【解决方案1】:

这个答案是对发生的聊天的回应。

以下是我的 servlet 代码

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.getWriter().println("Hello World");
            response.getWriter().flush();
            response.getWriter().close();
    }

以下是我的连接代码,它可以工作。

public static void main(String[] args) throws IOException {
    System.setProperty("http.proxyHost", "proxy.***.com");
    System.setProperty("http.proxyPort", "####");
     Authenticator authenticator = new Authenticator() {
                    public PasswordAuthentication getPasswordAuthentication() {
                        return (new PasswordAuthentication("user",
                                "pwd".toCharArray()));
                    }
                };
    Authenticator.setDefault(authenticator);
     URL url = new URL( "http://localhost:8080/ImageCanvas/Servlet2" );
     BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
     String line;
     while((line=br.readLine())!= null){
         System.out.println(line);
         System.out.flush();
     }
     br.close();

}

【讨论】:

  • 是的,我正在尝试做同样的事情,但是,是的,我的项目周期从一个用作 JMS 消息生产者的 Java 类开始,我在其中使用代码设置了一些初始上下文参数:Hashtable ht =新哈希表(); ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL, "t3://localhost:7001"); ctx = new InitialContext(ht); :::::::::::: 可能这有问题???
猜你喜欢
  • 2017-06-21
  • 2018-10-27
  • 1970-01-01
  • 2019-03-14
  • 2015-10-13
  • 1970-01-01
  • 2021-12-17
  • 1970-01-01
  • 2021-12-12
相关资源
最近更新 更多