我正在努力使用带有应用程序引擎的基本 crud 方法:
我的代码如下所示:
我的客户控制器:
@Controller
public class CustomerController {
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String getAddCustomerPage(ModelMap model) {
return "command";
}
@RequestMapping(value = "/list", method = RequestMethod.POST)
public ModelAndView add(HttpServletRequest request, ModelMap model) {
String email = request.getParameter("email");
String password = request.getParameter("password");
Customer c = new Customer();
c.setEmail(email);
c.setPassword(password);
c.setDate(new Date());
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(c);
} finally {
pm.close();
}
return new ModelAndView("redirect:command");
}
// get all customers
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String listCustomer(ModelMap model) {
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = pm.newQuery(Customer.class);
q.setOrdering("date desc");
List<Customer> results = null;
try {
results = (List<Customer>) q.execute();
if (results.isEmpty()) {
model.addAttribute("customerList", null);
} else {
model.addAttribute("customerList", results);
}
} finally {
q.closeAll();
pm.close();
}
return "list";
}
我的 mvc-dispatcher-servlet:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.Trium.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
以及我想在 command.jsp 中处理的表单:
<form id="myForm" class="form-horizontal" action="add"
method="post">
<fieldset>
<div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">Email:</label>
<div class="controls">
<input name="email" placeholder="email"
class="input-xlarge" type="text"
value="<%=request.getParameter("email")%>">
</div>
</div>
<div class="control-group">
<!-- Text input-->
<label class="control-label" for="input01">Password:</label>
<div class="controls">
<input name="password" placeholder="password"
class="input-xlarge" type="text"
value="<%=request.getParameter("password")%>">
</div>
</div>
</fieldset>
</form>
当我想从http://127.0.0.1:8888/command.jsp
. 我得到:
http://127.0.0.1:8888/add
错误 404
在 GAE 我得到:
警告:在名称为“mvc-dispatcher”的 DispatcherServlet 中未找到带有 URI [/add] 的 HTTP 请求的映射
请帮助我找出我的应用程序中错误映射的内容。
更新
<?xml version="1.0" encoding="UTF-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Servlets -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>
更新 - 2
Mär 26, 2013 4:59:11 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: Initializing Spring root WebApplicationContext
Mär 26, 2013 4:59:11 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Mär 26, 2013 4:59:17 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue Mar 26 16:59:17 UTC 2013]; root of context hierarchy
Mär 26, 2013 4:59:19 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
Mär 26, 2013 4:59:21 PM org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
Mär 26, 2013 4:59:25 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Mär 26, 2013 4:59:25 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7f5fde46: defining beans [customerController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/list],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.add(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/delete/{key}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.delete(java.lang.String,javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/update],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.update(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/add],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.Trium.controller.CustomerController.getAddCustomerPage(org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/update/{name}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.Trium.controller.CustomerController.getUpdateCustomerPage(java.lang.String,javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/list],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.Trium.controller.CustomerController.listCustomer(org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:27 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/login],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.login(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:30 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 18804 ms
Mär 26, 2013 4:59:37 PM com.google.appengine.tools.development.ApiProxyLocalImpl log
INFO: javax.servlet.ServletContext log: Initializing Spring FrameworkServlet 'mvc-dispatcher'
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization started
Mär 26, 2013 4:59:37 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Tue Mar 26 16:59:37 UTC 2013]; parent: Root WebApplicationContext
Mär 26, 2013 4:59:37 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]
Mär 26, 2013 4:59:37 PM org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
Mär 26, 2013 4:59:37 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
Mär 26, 2013 4:59:37 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@3c050a95: defining beans [customerController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@7f5fde46
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/list],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.add(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/delete/{key}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.delete(java.lang.String,javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/update],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.update(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/add],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.Trium.controller.CustomerController.getAddCustomerPage(org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/update/{name}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.Trium.controller.CustomerController.getUpdateCustomerPage(java.lang.String,javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/list],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.Trium.controller.CustomerController.listCustomer(org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:37 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/login],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.Trium.controller.CustomerController.login(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap)
Mär 26, 2013 4:59:38 PM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 657 ms
Mär 26, 2013 4:59:38 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Started SelectChannelConnector@0.0.0.0:8888
Mär 26, 2013 4:59:38 PM com.google.appengine.tools.development.AbstractServer startup
INFO: Server default is running at http://localhost:8888/
Mär 26, 2013 4:59:38 PM com.google.appengine.tools.development.AbstractServer startup
INFO: The admin console is running at http://localhost:8888/_ah/admin
Mär 26, 2013 5:59:38 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: Dev App Server is now running
Mär 26, 2013 6:00:11 PM org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported
现在我得到了一个不同的例外。但是,我和以前没有任何改变;P
**WARNING: Request method 'POST' not supported**