REQUEST.GETREMOTEADDR () Get some problems with IP address

Source: Internet
Author: User
My Tomcat version is 6.0.
When using REQUEST.GETREMOTEADDR () to obtain an IP address under WIN7, the value that may be returned is not the IP we want, but rather the 0:0:0:0:0:0:0:1 of such a string value. This is the address of the IPv6 agreement, unfortunately we want to need is similar to 127.0.0.1 such IP address. In fact, this situation only occurs when your server and your client are the same machine, only in this case.
The reason is because C:\Windows\System32\drivers\etc\hosts this file, there are two lines in this file:

# 127.0.0.1 localhost

#:: 1 localhost


These two are actually one for IPV6, and one for IPV4. If it is the Win7 system, the default will be IPV6 so we get the value of this place is 0:0:0:0:0:0:0:1,XP does not appear this problem.
Method One (test effective, 360 will report domain name redirection, Firefox, ie not reported):
If the Win7 solution is to delete #::1 localhost this line of content, or to keep this behavior annotation state, and cancel #127.0.0.1 localhost The #号注释 of this line. Most articles on the web say that the approach here is to cancel this line of comment. If you simply uncomment, the IPV6 protocol is used to connect, which may cause your database connection to be wrong.
Of course, this place is mainly a problem that Win7 will encounter. Because only Win7 is used IPV6.
Method Two (untested):
Add in local tomcat parameter:-djava.net.preferipv4stack=true let tomcat only support ipV4.
Method Three (this method is the easiest and most effective and secure):
In the browser without locahost to access, but directly input 127.0.0.1 to access can also achieve the same effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.