gpt4 book ai didi

java - HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST

转载 作者:行者123 更新时间:2023-12-02 09:06:25 25 4
gpt4 key购买 nike

我尝试发送一些数据,但似乎无法清楚地找到 Controller 或无法处理请求。

测试.jsp

<%@ page errorPage="exception.jsp"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page session="true" import="java.io.*,java.util.*"%>
<%@ page import="eng.ku.sku.exceed_vote.knt.*"%>


<form name="AddForm" action="addtext" method="POST">
<input type="hidden" name="todo" value="add">

Add text:<input type="text" name="text" />

<input type="submit" value="Add">
</form>

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>exceed</servlet-name>
<servlet-class>eng.ku.sku.exceed_vote.knt.Controller</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>exceed</servlet-name>
<url-pattern>/addtext</url-pattern>

Controller .java

package eng.ku.sku.exceed_vote.knt;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

@WebServlet("/addtext")
public class Controller extends HttpServlet {
private static final long serialVersionUID = 1L;

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response); // Same as doPost()
}

@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

// Retrieve the current session, or create a new session if no session exists.
HttpSession session = request.getSession(true);
System.out.println("HIIEER");
// Retrieve the shopping cart of the current session.


// For dispatching the next Page
String nextPage = "";
String todo = request.getParameter("todo");

// Dispatch to checkout.jsp
nextPage = "/checkout.jsp";

response.sendRedirect(nextPage);
return;
}
}

我阅读了很多其他主题,但没有找到解决方案。我希望你能帮助我:)

最佳答案

好吧,这是 Tomcat 的错误配置。

它没有同步项目更改。

关于java - HTTP 状态 405 - 此 URL 不支持 HTTP 方法 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12429057/

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