本地主机拒绝连接-ERR_CONNECTION_REFUSED [英] localhost refuses to connect - ERR_CONNECTION_REFUSED

查看:429
本文介绍了本地主机拒绝连接-ERR_CONNECTION_REFUSED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的MVC Web应用程序,其中javascript代码将ajax请求发送到控制器,并且控制器发送回响应.

2年前,我开发了该应用程序,并且一切正常.现在,我尝试再次在本地运行该应用程序,并遇到以下问题:每当Ajax请求从前端发送到控制器(在localhost上运行)时,localhost拒绝连接,我在(chrome的)javascript控制台中收到ERR_CONNECTION_REFUSED消息.(在Safari的javascript控制台中,我收到以下错误消息:无法加载资源:无法连接到服务器.")

我正在使用NetBeans 11.2运行该应用程序.我的NetBeans IDE使用GlassFish作为服务器:

我从NetBeans IDE中删除了Glassfish服务器,删除了它在主目录中的文件夹,然后在我的NetBeans IDE中再次添加了Glassfish服务器(这也需要下载最新版本的Glassfish服务器).

仍然,服务器拒绝接受来自前端的任何请求.

我也尝试使用Payara Server(版本5.193).那也没什么不同.

乍一看,前端本身看起来还不错.也就是说,转到

这到底是怎么回事?!

解决方案

您之前使用过端口8081,然后将变量"url"更改为新的端口8080吗?在这种情况下,变量可能仍设置为高速缓存中的旧值.重新启动计算机,然后查看是否可以解决问题.

I have a simple MVC web application where javascript code sends ajax requests to the controller and the controller sends back responses.

I built the app 2 years ago and everything used to work fine. Now I tried to run the app again locally and met with the following problem: whenever an Ajax request is sent from the frontend to the controller (running on localhost), the localhost refuses to connect and I get an ERR_CONNECTION_REFUSED message in (chrome's) javascript-console. (In Safari's javascript-console I get the following error message: "Failed to load resource: Could not connect to the server.")

I'm running the app using NetBeans 11.2. My NetBeans IDE uses GlassFish as server:

I removed the Glassfish server from NetBeans IDE, deleted its folder in my home directory and then added the Glassfish server again in my NetBeans IDE (which also entailed downloading the the newest version of the Glassfish server).

Still, the server refuses to accept any requests from the frontend.

I also tried using Payara Server (version 5.193). That didn't make a difference either.

The frontend itself looks fine at first glance by the way. That is, going to http://localhost:8080/myapp loads the frontend of the app. However, any dynamic features of the app don't work because the server refuses to accept any Ajax requests coming from the frontend (and initiated through mouse clicks).

How can I fix this?


I think I found the reason for the problem:

In my javascript-file I have the following line of code:

var url = "http://localhost:8080/myapp/Controller";

The variable "url" is passed to all the AJAX requests sent to localhost. But here is the crazy thing: the AJAX requests are not sent to "http://localhost:8080/myapp/Controller" but to "http://localhost:8081/myapp/Controller" !!!!!

What the hell is going on here?!

解决方案

Did you use port 8081 before and then changed the variable "url" to the new port 8080? In this case, maybe the variable is still set to the old value in the cache. Restart your computer and see whether this fixes the problem.

这篇关于本地主机拒绝连接-ERR_CONNECTION_REFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆