request.getRemoteAddr()返回一个String 是本机地址要想得到服务器的地址:import java.net.*;
public class catchserverip{
InetAddress ServerIPaddress=null;
//取得Server的IP地址
public InetAddress getServerIP() {
try { ServerIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (ServerIPaddress);
}
}就可以了
在jsp中写
<jsp:useBean id="catchipbean" scope="page" class="catchip" />
String servername=catchipbean.getServerIP().getHostName();
public class catchserverip{
InetAddress ServerIPaddress=null;
//取得Server的IP地址
public InetAddress getServerIP() {
try { ServerIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (ServerIPaddress);
}
}就可以了
在jsp中写
<jsp:useBean id="catchipbean" scope="page" class="catchip" />
String servername=catchipbean.getServerIP().getHostName();
String userIP=request.getRemoteHost();可以得到服务器的机器名
谢谢!!!luka_l(浪尖折腾),zhaoweiemail(剑心)
特别是luka_l(浪尖折腾)多次的帮助,谢谢!!!有机会交个朋友?