[英]Why it is shown HTTP Status 405 - HTTP method POST is not supported by this URL?
I have worked on demo login application on spring. 我在春季从事过演示登录应用程序的工作。 This is my LoginController.java:
这是我的LoginController.java:
package com.pran.pal.controller;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class LoginController extends HttpServlet{
@RequestMapping(value="/login" ,method=RequestMethod.GET)
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {
String userName=request.getParameter("userName");
String password=request.getParameter("password");
String message;
if(userName != null && !userName.equals("") && userName.equals("admin")
&& password != null && !password.equals("") && password.equals("123")){
message = "Welcome " +userName + ".";
return new ModelAndView("index", "message", message);
}
else{
message = "Wrong username or password.";
return new ModelAndView("index", "message", message);
}
}
I have used eclipse Neon, Tomcat v9. 我使用过Eclipse Neon,Tomcat v9。
This is my pom.xml 这是我的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pran.pal</groupId>
<artifactId>LoginSystemPAL</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>LoginSystemPAL Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>LoginSystemPAL</finalName>
</build>
</project>
and this is my web.xml 这是我的web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>LoginController</servlet-name>
<servlet-class>com.pran.pal.controller.LoginController</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>LoginController</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
It has shown that input username and password that:
它显示输入的用户名和密码如下:
HTTP Status 405 - HTTP method POST is not supported by this URL
HTTP状态405-此URL不支持HTTP方法POST
type Status report
类型状态报告
message HTTP method POST is not supported by this URL
此URL不支持消息HTTP方法POST
description The specified HTTP method is not allowed for the requested resource.
说明所请求的资源不允许使用指定的HTTP方法。
How can I solve this problem? 我怎么解决这个问题?
Your <servlet-class>
should be com.pran.pal.controller.LoginController
, but you should also have a dependency to Spring Web from here . 您的
<servlet-class>
应该是com.pran.pal.controller.LoginController
,但是您还应该从此处对Spring Web有依赖性。
Also, you are not using properly the Spring @Controller
annotation. 另外,您没有正确使用Spring
@Controller
批注。 Please follow a step by step tutorial like the one here . 请按照此处的逐步教程进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.