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.
try adding this parameter -Djava.net.preferIPv4Stack=true
to your tomcat startup commandline.
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