localhost跟127.0.0.1小问题

jiejiefala888 2012-07-18 10:30:00
最近遇到一个小问题,就是我用localhost当成网址打开页面做测试,但是我的网页js代码里面用了127.0.0.1做一个servlet请求,这时候神奇发现收不到response。我就结了很久,后来把ja代码中的127.0.0.1改成localhost才算成功了。我知道在做请求时候连ip都不用打,浏览器会帮你补全,但是为什么会出现这种bug呢,有点想不通。。大神们解疑下。
...全文
525 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qybao 2012-08-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
这里不是说了DNS会自己识别,为什么还要自己写上。。

引用 2 楼 的回复:

看看 hosts 文件
[/Quote]

你的DNS解析的lcalhost肯定不是你的机器(就算DNS默认配置了localhost也是DNS自己),你想,每台机器都叫localhost,你的DNS能智能地解析成哪台机器(除非DNS配置了解析到某台机器,否则DNS也解析不了)?
所以,这种情况,修改你的hosts文件,打开
127.0.0,1 localhost
就可以了
huangxw000 2012-08-02
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
看看 hosts 文件
最后一行
127.0.0.1 localhost
[/Quote]+1
k7626360k 2012-08-02
  • 打赏
  • 举报
回复
看看 hosts 文件
最后一行
127.0.0.1 localhost
yza3137957 2012-07-31
  • 打赏
  • 举报
回复
不爱结贴是个什么习惯
jueshengtianya 2012-07-31
  • 打赏
  • 举报
回复
客户端会先去查找hosts这个文件,然后才去找DNS
VanBaston 2012-07-31
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
这里不是说了DNS会自己识别,为什么还要自己写上。。

引用 2 楼 的回复:

看看 hosts 文件
[/Quote]
但是你没有DNS啊
你的127.0.0.1和你的localhost不是一个东西啊
jiejiefala888 2012-07-31
  • 打赏
  • 举报
回复

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
这里不是说了DNS会自己识别,为什么还要自己写上。。
[Quote=引用 2 楼 的回复:]

看看 hosts 文件
[/Quote]
五哥 2012-07-19
  • 打赏
  • 举报
回复
查看
C:\WINDOWS\system32\drivers\etc\hosts

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost
achao818 2012-07-19
  • 打赏
  • 举报
回复
看看 hosts 文件
jiejiefala888 2012-07-18
  • 打赏
  • 举报
回复
我用127.0.0.1当成网址打开页面做测试,但是我的网页js代码里面用了localhost做一个servlet请求,这时候也是发现收不到response。。就是说访问网址请求的要始终保持一致,不然就收不到response、、

67,549

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧