0

我有一个由 Spring 处理的 sevlet,并且还使用 Google App Engine 作为云平台。

我想将此 servlet 重定向到另一个页面:

@Controller

公共类客户控制器 {

@RequestMapping(value = "/", method = RequestMethod.GET)
public String listAllFeedsOnIndexPage(ModelMap map) throws JSONException {
   return "invite";
}

@RequestMapping(method = RequestMethod.GET)
public ModelAndView add(HttpServletRequest request, ModelMap model) {

    String firstName = request.getParameter("firstName");
    String lastName = request.getParameter("lastName");
    String email = request.getParameter("email");

    System.out.println(email);
    System.out.println(firstName);
    System.out.println(lastName);

    Customer c = new Customer();
    c.setFirstName(firstName);
    c.setLastName(lastName);
    c.setEmail(email);
    c.setDate(new Date());

    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
        pm.makePersistent(c);
    } finally {
        pm.close();
    }

    return new ModelAndView("redirect:thankYou");

}

My App Engine output: Initializing App Engine server Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.config.EarHelper logNotAnEar INFO: Directory 'C:\Users\user\workspace\LandingPage\war' is not an EAR directory. File C:\Users\user\workspace\LandingPage\war\appengine-application.xmlappengine-application.xml not detected. Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.config.EarHelper logNotAnEar INFO: Directory 'C:\Users\user\workspace\LandingPage\war' is not an EAR directory. File C:\Users\user\workspace\LandingPage\war\appengine-application.xmlappengine-application.xml not detected. Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.config.EarHelper logNotAnEar INFO: Directory 'C:\Users\user\workspace\LandingPage\war' is not an EAR directory. File C:\Users\user\workspace\LandingPage\war\appengine-application.xmlappengine-application.xml not detected. Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.config.EarHelper logNotAnEar INFO: Directory 'C:\Users\user\workspace\LandingPage\war' is not an EAR directory. File C:\Users\user\workspace\LandingPage\war\appengine-application.xmlappengine-application.xml not detected. Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml INFO: Successfully processed C:\Users\user\workspace\LandingPage\war\WEB-INF/appengine-web.xml Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml INFO: Successfully processed C:\Users\user\workspace\LandingPage\war\WEB-INF/web.xml Mär 30, 2013 1:28:26 PM com.google.appengine.tools.development.SystemPropertiesManager setSystemProperties INFO: Overwriting system property key 'java.util.logging.config.file', value 'C:\Users\user\Desktop\eclipse-java-juno-SR1-win32-x86_64\eclipse\plugins\com.google.appengine.eclipse.sdkbundle_1.7.5\appengine-java-sdk-1.7.5\config\sdk\logging.properties' with value 'WEB-INF/logging.properties' from 'C:\Users\user\workspace\LandingPage\war\WEB-INF\appengine-web.xml' Mär 30, 2013 1:28:26 PM com.google.apphosting.utils.jetty.JettyLogger info INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger Mär 30, 2013 12:28:27 PM com.google.apphosting.utils.jetty.JettyLogger info INFO: jetty-6.1.x Mär 30, 2013 12:28:28 PM com.google.appengine.tools.development.ApiProxyLocalImpl log INFO: javax.servlet.ServletContext log: Initializing Spring root WebApplicationContext Mär 30, 2013 12:28:28 PM org.springframework.web.context.ContextLoader initWebApplicationContext INFO: Root WebApplicationContext: initialization started Mär 30, 2013 12:28:29 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh INFO: Refreshing Root WebApplicationContext: startup date [Sat Mar 30 12:28:29 UTC 2013]; root of context hierarchy Mär 30, 2013 12:28:29 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] Mär 30, 2013 12:28:29 PM org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning Mär 30, 2013 12:28:30 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring Mär 30, 2013 12:28:30 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@9b4ed7a: 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 30, 2013 12:28:31 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod INFO: Mapped "{[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.landing.controller.CustomerController.add(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap) Mär 30, 2013 12:28:31 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod INFO: Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.landing.controller.CustomerController.listAllFeedsOnIndexPage(org.springframework.ui.ModelMap) throws com.google.appengine.labs.repackaged.org.json.JSONException Mär 30, 2013 12:28:31 PM org.springframework.web.context.ContextLoader initWebApplicationContext INFO: Root WebApplicationContext: initialization completed in 3010 ms Mär 30, 2013 12:28:32 PM com.google.appengine.tools.development.ApiProxyLocalImpl log INFO: javax.servlet.ServletContext log: Initializing Spring FrameworkServlet 'mvc-dispatcher' Mär 30, 2013 12:28:32 PM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet 'mvc-dispatcher': initialization started Mär 30, 2013 12:28:32 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh INFO: Refreshing WebApplicationContext for namespace 'mvc-dispatcher-servlet': startup date [Sat Mar 30 12:28:32 UTC 2013]; parent: Root WebApplicationContext Mär 30, 2013 12:28:32 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] Mär 30, 2013 12:28:32 PM org.springframework.context.annotation.ClassPathBeanDefinitionScanner registerDefaultFilters INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning Mär 30, 2013 12:28:32 PM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring Mär 30, 2013 12:28:32 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d3f82cd: 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@9b4ed7a Mär 30, 2013 12:28:32 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod INFO: Mapped "{[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.landing.controller.CustomerController.add(javax.servlet.http.HttpServletRequest,org.springframework.ui.ModelMap) Mär 30, 2013 12:28:32 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod INFO: Mapped "{[/],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.landing.controller.CustomerController.listAllFeedsOnIndexPage(org.springframework.ui.ModelMap) throws com.google.appengine.labs.repackaged.org.json.JSONException Mär 30, 2013 12:28:32 PM org.springframework.web.servlet.DispatcherServlet initServletBean INFO: FrameworkServlet 'mvc-dispatcher': initialization completed in 520 ms Mär 30, 2013 12:28:32 PM com.google.apphosting.utils.jetty.JettyLogger info INFO: Started SelectChannelConnector@0.0.0.0:8888 Mär 30, 2013 12:28:32 PM com.google.appengine.tools.development.AbstractServer startup INFO: Server default is running at http://localhost:8888/ 2013 年 3 月 30 日下午 12:28:32 com.google.appengine.tools.development.AbstractServer 启动信息:管理控制台在 http:// 运行localhost:8888/_ah/admin 2013 年 3 月 30 日下午 1:28:32 com.google.appengine.tools.development.DevAppServerImpl 开始信息:开发应用服务器现在正在运行 null null null null null null 2013 年 3 月 30 日 1:28: 39 PM com.google.appengine.api.datastore.dev.LocalDatastoreService 初始化信息:本地数据存储已初始化:类型:高复制存储:C:\Users\user\workspace\LandingPage\war\WEB-INF\appengine-generated\local_db .bin 2013 年 3 月 30 日下午 1:28:39 com.google.appengine.api.datastore.dev.LocalDatastoreService 加载信息:后备存储,C:\Users\user\workspace\LandingPage\war\WEB-INF\appengine -生成\local_db.bin,不存在。它将被创建。null null null null null null null

However, when I press enter in my form. I get one entry of the data and A LOT OF null entries. It seems to me that the redirect, does not redirect to the other page, it recursively redirects back.

Any idea how to fix that behaviour?

4

1 回答 1

1

You can try something like this. I am returning a success page on successful form post.

@RequestMapping(value="sendData" ,method = RequestMethod.POST)
public String add(HttpServletRequest request, ModelMap model) {

String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String email = request.getParameter("email");

System.out.println(email);
System.out.println(firstName);
System.out.println(lastName);

Customer c = new Customer();
c.setFirstName(firstName);
c.setLastName(lastName);
c.setEmail(email);
c.setDate(new Date());

PersistenceManager pm = PMF.get().getPersistenceManager();
try {
    pm.makePersistent(c);
} finally {
    pm.close();
}

return "successpage";
}
于 2013-03-30T19:13:55.883 回答