gpt4 book ai didi

java - Apache Tomcat 405 错误

转载 作者:行者123 更新时间:2023-11-28 23:55:58 32 4
gpt4 key购买 nike

我正在尝试在 ecclipse IDE 上运行时出现 Apache 405 错误...下面是我的 servlet 代码。

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class MyFirstServlet extends HttpServlet {
public void Service(HttpServletRequest request,HttpServletResponse response)throws IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.write("<html>");
out.write("<title>Welcome</title>");
out.write("<body bgcolor=blue>");
out.write("<h1>Hi Wassup</h1><br>");
out.write("<h2>Great that you are studying Java</h2>");
out.write("</body>");
out.write("</html>");
out.close();


}

}

下面是我的 web.xml 文件。

<web-app>
<servlet>
<servlet-name>firstservlet</servlet-name>
<servlet-class>MyFirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>firstservlet</servlet-name>
<url-pattern>/homepage</url-pattern>]
</servlet-mapping>
</web-app>

有人请帮我解决这个问题..因为我是第一次尝试。提前致谢

最佳答案

您已经在 servlet 的构造函数中实现了响应 HTML。您实际需要做的是实现 doGet/doPost 方法并将您的代码放入其中。

喜欢

protected void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.write("<html>");
out.write("<title>Welcome</title>");
out.write("<body bgcolor=blue>");
out.write("<h1>Hi Wassup</h1><br>");
out.write("<h2>Great that you are studying Java</h2>");
out.write("</body>");
out.write("</html>");
out.close();
}

关于java - Apache Tomcat 405 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22117608/

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