[J2SE] tomcat改80 port

看板java作者 (大熊)時間13年前 (2012/07/28 14:29), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
環境 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

07/28 15:16, , 1F
你要不要先用 browser 連連,看 server 是否正常
07/28 15:16, 1F

07/28 15:24, , 2F
有阿~我把eclipse中的網址複製到瀏覽器 可以開
07/28 15:24, 2F
文章代碼(AID): #1G4uRdlE (java)