gpt4 book ai didi

java - 将 Servlet 重定向到 div 容器

转载 作者:行者123 更新时间:2023-12-01 14:43:22 24 4
gpt4 key购买 nike

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

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

@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
<init> 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
<init> 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/ 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

但是,当我在表单中按 Enter 时。我得到了一个数据条目和很多 null 条目。在我看来,重定向并没有重定向到其他页面,而是递归地重定向回来。

知道如何解决这个问题吗?

最佳答案

你可以尝试这样的事情。我正在成功发布表单后返回成功页面。

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

关于java - 将 Servlet 重定向到 div 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15718588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com