gpt4 book ai didi

eclipse - 此 URL 不支持具有简单 servlet 的 HTTP 方法 GET

转载 作者:行者123 更新时间:2023-11-29 00:02:00 25 4
gpt4 key购买 nike

自 2 天以来,我一直在尝试解决这个问题,在 stackoverflow 上的许多帖子中都有相同的问题标题,但它们都是不同的,因为它们总是在代码中出错,但就我而言,我有一个示例servlet,当我运行项目时出现此错误

HTTP Status 405 - HTTP method GET is not supported by this URL this is my class servlet

    package web;

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 Controller extends HttpServlet{

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public void init() throws ServletException {

}

@Override
protected void doGet(HttpServletRequest requet, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out =response.getWriter();
out.println("hello");
}

}

和我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>test2</display-name>
<servlet>
<servlet-name>cs</servlet-name>
<servlet-class>web.Controller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cs</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>

请告诉我如何解决这个问题,谢谢......

最佳答案

简单的 doGet Servlet 或者您可以添加 try catch 博客来调试代码

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class logout extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{

try
{
PrintWriter out=response.getWriter();
response.setContentType("text/html;charset=UTF-8");
out.println("Hello");
}

catch(Exception e)
{
out.println(e.toString())
}
}
}

关于eclipse - 此 URL 不支持具有简单 servlet 的 HTTP 方法 GET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35399645/

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