【发布时间】:2018-02-28 08:04:06
【问题描述】:
我得到了这个 index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Store</title>
</head>
<body>
<form action="#" th:action="@{/redirectToAddProd}" method="post">
<input type="submit" value="Submit" />
</form>
</body>
</html>
我得到了这个 StoreController.java
@Controller
@RequestMapping("/")
public class StoreController {
@GetMapping("/")
public String index() {
return "index";
}
@GetMapping("/addProduct")
public String addProduct() {
return "addProduct";
}
@PostMapping("/redirectToAddProd")
public String redirectToAddProd() {
return "redirect:/addProduct";
}
}
我的问题是,当我按下提交按钮时,什么都没有发生(真的什么都没有),不是获取请求,甚至不是 404。你有解决方案吗? 谢谢
编辑: 我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 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>MyStore</display-name>
<servlet>
<servlet-name>store</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/store-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>store</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
编辑:现在我遇到了一个新错误。现在按钮做了一些事情,但给了我错误:
sept. 20, 2017 10:08:30 AM org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
AVERTISSEMENT: Request method 'POST' not supported
【问题讨论】:
标签: java html spring spring-mvc thymeleaf