作者gh8811211 (大熊)
看板java
标题[J2EE] tomcat改80 port
时间Sat Jul 28 14:29:56 2012
环境 eclipse + tomcat7
把Tomcat改80 port之後
eclipse中server端可以正常执行
但java使用HttpURLConnection连结到servlet之档案
却无法正常执行
程式码如下
URL url = new URL("
http://localhost/ServletServer/Server");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(),
"UTF-8");
out.write("username=kevin&password=pass");
out.flush();
out.close();
String strLine = "";
String strResponse = "";
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while ((strLine = reader.readLine()) != null)
{
strResponse += strLine + "\n";
}
System.out.print(strResponse);
错误讯息为:
Exception in thread "main" java.io.IOException: Invalid Http response
或是
Exception in thread "main" java.net.SocketException: Software caused
connection abort: recv failed
但在预设的8080 port中
就可以执行正常
不会有任何错误
请问为什麽会这样
敬请指教
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.100.86.102
1F:推 superlubu:你要不要先用 browser 连连,看 server 是否正常 07/28 15:16
2F:→ gh8811211:有阿~我把eclipse中的网址复制到浏览器 可以开 07/28 15:24