0
votes

I have a sevlet which is handled by Spring and also uses Google App Engine as a cloud plattform.

I want to redirect this servlet to another page:

@Controller

public class CustomerController {

@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 [email protected]: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/ Mär 30, 2013 12:28:32 PM com.google.appengine.tools.development.AbstractServer startup INFO: The admin console is running at http://localhost:8888/_ah/admin Mär 30, 2013 1:28:32 PM com.google.appengine.tools.development.DevAppServerImpl start INFO: Dev App Server is now running null null null null null null Mär 30, 2013 1:28:39 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init INFO: Local Datastore initialized: Type: High Replication Storage: C:\Users\user\workspace\LandingPage\war\WEB-INF\appengine-generated\local_db.bin Mär 30, 2013 1:28:39 PM com.google.appengine.api.datastore.dev.LocalDatastoreService load INFO: The backing store, C:\Users\user\workspace\LandingPage\war\WEB-INF\appengine-generated\local_db.bin, does not exist. It will be created. 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?

1
what is the action of your form ? does it also points to thankYou url ?Ankur Jain

1 Answers

1
votes

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";
}