Spring mvc 如何使用Spring MVC 3.1通过控制器传递表单数据-Spring MVC的新功能
我对spring和spring mvc都是新手。我使用的是3.1版。另外,目前我正在使用Tomcat7和MySQL5.5。我在数据库表中有数据,可以在网页上显示。现在,我正在尝试从web表单向数据库添加数据,然后在网页上显示这些数据 以下是我尝试调用web表单时出现的部分运行时错误: **根本原因是:org.springframework.web.HttpRequestMethodNotSupportedException:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.resolveHandlerMethodAnnotationMethodHandlerAdapter.java:665 atorg.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethodAnnotationMethodHandlerAdapter.java:431位于org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleAnnotationMethodHandlerAdapter.java:424位于org.springframework.web.servlet.DispatcherServlet.doDispatcherservlet.java:900位于org.springframework.web.servlet.DispatcherServlet.doServiceDispatcherServlet.java:827位于org.springframework.web.servlet.FrameworkServlet.processRequestFrameworkServlet.java:882位于org.springframework.web.servlet.FrameworkServlet.doGetFrameworkServlet.java:778在javax.servlet.http.HttpServlet.serviceHttpServlet.java:621在javax.servlet.http.HttpServlet.serviceHttpServlet.java:722在 这是我的控制器有问题的部分。注意,如果我只有@RequestMapping/newProfile行,而不是另一个@RequestMapping行,那么我会得到一个没有显示数据的网页,这是我所期望的,因为我还没有插入DAO层Spring mvc 如何使用Spring MVC 3.1通过控制器传递表单数据-Spring MVC的新功能,spring-mvc,Spring Mvc,我对spring和spring mvc都是新手。我使用的是3.1版。另外,目前我正在使用Tomcat7和MySQL5.5。我在数据库表中有数据,可以在网页上显示。现在,我正在尝试从web表单向数据库添加数据,然后在网页上显示这些数据 以下是我尝试调用web表单时出现的部分运行时错误: **根本原因是:org.springframework.web.HttpRequestMethodNotSupportedException:org.springframework.web.servlet.mvc.
@RequestMapping(value = "/newProfile", method = {RequestMethod.POST})
//@RequestMapping("/newProfile")
public String addNewProfile(@ModelAttribute("profile")Profile profile, ModelMap model) {
model.addAttribute("firstName", profile.getFirstName());
model.addAttribute("lastName", profile.getLastName());
return "newProfileResult";
}
以下是我目前使用JSP的输入web表单:
异常表明Spring找不到GET请求的映射。我假设您在浏览器中输入just/newProfile。这将导致GET请求。提供GET请求的映射。您可以通过单独的映射来实现这一点,或者在编写ommit方法时实现这一点
<%@ include file="/WEB-INF/jsp/includes.jsp" %>
<%@ include file="/WEB-INF/jsp/header.jsp" %>
<html>
<head>
<title>Profile Test</title>
</head>
<body>
<h2>Information</h2>
<form:form method="POST" action="/newProfile">
<table>
<tr>
<td><form:label path="firstName">First Name</form:label></td>
<td><form:input path="firstName" /></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form:form>
</body>