HttpServletRequest.getRemoteAddr() in Tomcat retur

2019-02-11 05:37发布

HttpServletRequest.getRemoteAddr() in Tomcat returns IPv6 formatted IP address, but I would like to configure it that returns IPv4.

I access the servlet via 'localhost'. If I access it via '127.0.0.1' then returns IPv4 formatted IP address (see this answer).

Environment:

  • Windows 7 x64
  • Tomcat 6.0.35-windows-x64

My LAN connection properties: IPv6 is checked off, but it doesn't work neither if I check it on.

My LAN connection properties

2条回答
三岁会撩人
2楼-- · 2019-02-11 05:58

try adding this parameter -Djava.net.preferIPv4Stack=true to your tomcat startup commandline.

查看更多
smile是对你的礼貌
3楼-- · 2019-02-11 06:18

when you use localhost/xxx, your browser first have to find the mapped address for the name "localhost".In system host file you will find:

# 127.0.0.1 localhost

# ::1 localhost

both definition disabled by default.

to change browser's default matching rules, you have to enable the definition.

e.g: remove "#" from the first host file line, your brower will know directily "localhost" equals 127.0.0.1

Cheers

查看更多
登录 后发表回答