2

我正在使用下面的代码从我的 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'  

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

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

谢谢!!!

4

1 回答 1

0

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

以下是我的 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();

}
于 2014-05-06T05:28:41.703 回答