【发布时间】:2021-06-29 06:25:52
【问题描述】:
错误->
HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET 输入状态报告
此 URL 不支持消息 HTTP 方法 GET
说明 请求的资源不允许使用指定的 HTTP 方法。
web.xml
<!-- webapp/WEB-INF/web.xml -->
<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_3_0.xsd"
version="3.0">
<display-name>To do List</display-name>
<welcome-file-list>
<welcome-file>login.do</welcome-file>
</welcome-file-list>
</web-app>
LoginServlet.java
package com.todo;
//imports ->
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// url ->
@WebServlet(urlPatterns = "/login.do")
// response genrator ->
public class LoginServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {{
// JSP code response ->
RequestDispatcher RequetsDispatcherObj =request.getRequestDispatcher("/WEB-INF/veiws/login.jsp");
RequetsDispatcherObj.forward(request, response); }
}
}
login.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>hello world from jsp</title>
</head>
<body>
<p>
Hello world from jsp!
</p>
</body>
</html>
【问题讨论】:
-
代码块很好。但请尝试添加您尝试过的和无效的。