gpt4 book ai didi

java - Apache Tomcat 9.0 端口已在使用中

转载 作者:行者123 更新时间:2023-11-28 22:26:20 24 4
gpt4 key购买 nike

我知道这是一个常见问题,我知道有很多解决它的建议。不幸的是,没有一个对我有用。

我用 netstat -ano 检查了我需要的端口是否已经繁忙并且它们被我唯一的 Tomcat session 占用(如我所料)。我试图关闭 tomcat 只是为了无法重新启动它(从任务管理器的服务页面它不会再次启动,它会继续从被捕到运行再到被捕)。我尝试从服务器 View 和 server.xml 更改 Eclipse 上的端口,但没有成功。我得到的唯一结果是 Tomcat 在几次切换后崩溃(除非我重新启动我的笔记本电脑,否则不会恢复在线,如上所述)。

有什么线索吗?

--编辑--

这是一些代码

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WelcomeServlet extends HttpServlet{
// Elabora richieste "get" dai client
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

// Spedisce pagina XHTML al client

// Inizio documento XHTML
out.println("<?xbl version = \"1.0\"?>");

out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD "+"XHTML 1.0 Strict//EN\" \"http://www.w3.org"+"/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
out.println("<html xmlns = \"http://www.w3.org/1999/xhtml\">");

// sezione head del docuento
out.println("<head>");
out.println("<title>A Simple Servlet Example</title>");
out.println("</head>");

// sezione body del documento
out.println("<body>");
out.println("<h1>Welcome to Servlets!</h1>");
out.println("</body>");

// fine documento XTHML
out.println("</html>");
out.close(); //close stream to complete the page
}
}

如您所见,这是一段非常简单的代码,是我的第一个 servlet。

下面是 server.xml 连接端口:

<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

最后,这是 Eclipse 服务器 View

enter image description here

最佳答案

好的,我设法解决了。

我不得不从任务管理器中停止 apache tomcat 进程,因为这是持有端口的进程。它对我不起作用的原因是由于某种原因我的项目中没有 index.html 或类似文件。我所要做的就是创建一个 html 页面并将其添加到 web.xml 欢迎文件列表中。

关于java - Apache Tomcat 9.0 端口已在使用中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43545025/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com