如果用XML来配,是这样的:
<access-constraint> <ip-filter> <enable>true</enable> <allow-access>true</allow-access> <ip-collection> <client-ip-address>192.168.1.20</client-ip-address> </ip-collection> </ip-filter> </access-constraint>
如果用代码来写,就这样:
AccessConstraintConfig accessConstraintConfig = new AccessConstraintConfig(); IpFilterConfig ipFilterConfig = new IpFilterConfig(); ipFilterConfig.setEnable(true); ipFilterConfig.setAllowAccess(true); ipFilterConfig.addClientIpAddress("192.168.1.20"); accessConstraintConfig.setIpFilterConfig(ipFilterConfig); server.setAccessConstraintConfig(accessConstraintConfig);
要注意,QuickServer中,本机实际地址和127.0.0.1这个地址是区别对待的。若本机IP是192.168.1.20:
1.若本机以 telnet 192.168.1.20 方式访问服务器,则应添加的IP是 192.168.1.20
2.若本机以 telnet localhost 方式访问服务器,则应添加的IP是 127.0.0.1