JSP: new Socket (“www”, 80); stopped working after years of working OK
问题 In a JSP app, in Tomcat, the following code used to produce the whole address of the page (from this answer): String myUrl = "no network"; try { Socket s = new Socket("www", 80); myUrl = "http://"+s.getLocalAddress().getHostAddress()+":"+request.getLocalPort()+request.getRequestURI(); s.close(); } catch (Exception ex) { } finally { } After that miUrl would have the folowing value (not the real IP addr): http://111.101.101.2:8080/mypage.jsp It has been working for several years. A week ago