java 为什么 http://localhost:8080 可用而 127.0.0.1 不可用?(MyEclipse+Tomcat上的JSP)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1959223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 18:43:05  来源:igfitidea点击:

Why http://localhost:8080 available while 127.0.0.1 not? (JSP on MyEclipse+Tomcat)

javajsptomcatlocalhostmyeclipse

提问by Aloong

The System's hosts file is fine, 127.0.0.1 localhostis there...
Ping 127.0.0.1,or my IP, the result is also fine..
Myeclipse's version is 8.0 and I'm just using the Tomcat within it.
A simple JSP+Javabean web project sois deployed.

系统的hosts文件没问题,127.0.0.1 localhost有没有...
Ping 127.0.0.1,或者我的IP,结果也很好...
Myeclipse的版本是8.0,我只是在里面使用Tomcat。部署了
一个简单的JSP+Javabean web项目so

Now the situation is when I open MyEclipse and start the Tomcat, I can access my site throuth http://localhost:8080/so/index.jsp, and it displays and runs well (this means 8080 port is all right,right?).But http://127.0.0.1:8080/so/index.jspis a blank page(no source code) in K-Meleon and the page can't be found in IE.

现在的情况是,当我打开MyEclipse并启动Tomcat时,我可以访问我的站点 http://localhost:8080/so/index.jsp,并且显示和运行良好(这意味着8080端口没问题,对吧?)。但是http://127.0.0.1:8080/so/index.jsp是一个空白页面(没有源代码) K-Meleon 和该页面在 IE 中找不到。

Still when I tried to access it from another pc in LAN, 'http://myIP:8080/so/index.jsp', it worked only a little. The browser can load the homepage but without CSS, and clicking on any link or even refreshing the page leads to an error page..(While the site gose quite well on my own pc accessed throught localhost)

仍然当我尝试从 LAN 中的另一台电脑访问它时,' http://myIP:8080/so/index.jsp',它只工作了一点。浏览器可以加载主页但没有 CSS,单击任何链接甚至刷新页面都会导致错误页面..(虽然该站点在我自己的通过 localhost 访问的 PC 上运行良好)

Is there anyone have ever met this situation?

有没有人遇到过这种情况?

回答by bmargulies

If you configured tomcat to only listen on the non-loopback interface, this is what you'd get.

如果您将 tomcat 配置为仅侦听非环回接口,这就是您所得到的。

See thisdescription of how this gets configured in server.xml.

请参阅说明,了解如何在 server.xml 中对其进行配置。

Use the netstat -ato see what your tomcat is actually listening on.

使用netstat -a来查看您的 tomcat 实际在监听什么。