首页 > 应用开发 > IT综合 > webservice得到自身IP
由于业务需要我们的程序,使用了webservice技术,有一项业务需要在webservice中得到自身ip,(由于我们的server服务器比较多,这个ip不可指定)
解决:
[@more@]用jsp取到ip:
String gls_ip=request.getRemoteAddr();
System.out.println(gls_ip);
response.setHeader("GLS_IP",gls_ip);
return actionMapping.findForward("get_ip");
在webservice中取ip:
//get ip
// http://localhost:8080/fams/interface/gls/getGls_Ip.do
//java.net.URL url = new java.net.URL("http://10.104.0.117/get_ips/getip.do");
//java.net.HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
//String str_res = httpConnection.getHeaderField("GLS_IP");
//System.out.println(str_res + "-----------");
//return;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/300209/viewspace-850257/ ,如需转载,请注明出处,否则将追究法律责任。