如何修复java.io.FileNotFoundException:Response:';404:未找到';对于url:';http://localhost:7001/Socket-war/Servlet';
我使用下面的代码从Java类调用servlet:如何修复java.io.FileNotFoundException:Response:';404:未找到';对于url:';http://localhost:7001/Socket-war/Servlet';,java,url,filenotfoundexception,inputstreamreader,buffered,Java,Url,Filenotfoundexception,Inputstreamreader,Buffered,我使用下面的代码从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:7
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代码
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();
}
您可以从浏览器访问servlet吗?是的,使用浏览器我可以。您可以尝试127.0.0.1而不是localhost吗?另外,您的网络中是否存在任何代理设置?再次获取异常:java.io.FileNotFoundException:Response:'404:找不到位于weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:568)的weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:568)的url:'在weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:37)和java.net.URL.openStream(URL.java:1037)中,是的,我正在尝试做同样的事情,但是,是的,我的项目周期从一个java类开始,该类充当JMS消息生成器,我在其中使用代码:Hashtable ht=new Hashtable()设置一些初始上下文参数; put(Context.INITIAL\u Context\u工厂,“weblogic.jndi.WLInitialContextFactory”);put(Context.PROVIDER_URL,“t3://localhost:7001”);ctx=新的初始上下文(ht);:也许这有什么问题???