|
|
The error messages not show and input empty
I got a problem with Spring3MVC.
1. /loginInput initalize form data and forward to /loginInput.jsp
2. the jsp has form ,the form's action isquot;/Loginquot;
3. /login process the form a. validate the input ,if has error forward to /loginInput(inital form datas,then forward to /loginInput.jsp page,show the input data and error messages) b. no errors, load user imformations
some one can help me?
here i show the code:
web.xml
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;web-app version=quot;2.4quot; xmlns=quot;xml/ns/j2eequot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xsi:schemaLocation=quot;xml/ns/j2ee
xml/ns/j2ee/web-app_2_4.xsdquot;gt;
lt;context-paramgt;
lt;param-namegt;contextConfigLocationlt;/param-namegt;
lt;param-valuegt;/WEB-INF/classes/spring/spring-mvc.xmllt;/param-valuegt;
lt;/context-paramgt;
lt;listenergt;
lt;listener-classgt;org..web.context.ContextLoade rListenerlt;/listener-classgt;
lt;/listenergt;lt;!-- Spring #21047;#26032;Introspector#38450;#27490;#20839;#23384;#27945;#38706;--gt;
lt;listenergt; lt;listener-classgt;org..web.util.IntrospectorCle anupListenerlt;/listener-classgt;
lt;/listenergt;
lt;!-- Spring Serlvet --gt;
lt;servletgt;
lt;servlet-namegt;dispatcherServletlt;/servlet-namegt;
lt;servlet-classgt;org..web.servlet.DispatcherSe rvletlt;/servlet-classgt;
lt;init-paramgt;
lt;param-namegt;contextConfigLocationlt;/param-namegt;
lt;param-valuegt;/WEB-INF/classes/spring/spring-mvc.xmllt;/param-valuegt;
lt;/init-paramgt;
lt;load-on-startupgt;1lt;/load-on-startupgt;
lt;/servletgt;
lt;servlet-mappinggt;
lt;servlet-namegt;dispatcherServletlt;/servlet-namegt;
lt;ucl-patterngt;/lt;/ucl-patterngt;
lt;/servlet-mappinggt;
lt;welcome-file-listgt;
lt;welcome-filegt;index.jsplt;/welcome-filegt;
lt;/welcome-file-listgt;
lt;/web-appgt;
spring-mvc.xml
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns:mvc=quot;schema/mvcquot;
xmlns=quot;schema/pquot;
xmlns:context=quot;schema/contextquot;
xsi:schemaLocation=quot; schema/beans schem...-beans-3.0.xsd schema/context schem...ontext-3.0.xsd schema/mvc schema/mvc/spring-mvc-3.0.xsdquot;gt;
lt;context:component-scan base-package=quot;cn.testquot;/gt;
lt;!-- ControllerClassNameHandlerMapping#29992;#20110;#21305;#37197;#25105;#20204;#30340;Controller --gt; lt;bean class=quot;org..web.servlet.mvc.support .ControllerClassNameHandlerMappingquot; p:basePackage=quot;cn.test.webquot;/gt; lt;!-- #20351;#29992;annocation#21019;#24314;Controller#30340;bean --gt; lt;bean class=quot;org..web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapterquot;/gt;
lt;bean class=quot;org..web.servlet.view.Intern alResourceViewResolverquot; prefix=quot;/quot; p:suffix=quot;.jspquot; /gt;
lt;bean id=quot;messageSourcequot; class=quot;org..context.support.Resourc eBundleMessageSourcequot; p:basename=quot;messagesquot;/gt;
lt;mvc:annotation-driven/gt;
lt;/beansgt;
index.jsp
HTML Code:
lt;%@ page language=quot;javaquot; import=quot;java.util.*quot; pageEncoding=quot;UTF-8quot;%gt;
lt;!DOCTYPE HTML PUBLIC quot;-//W3C//DTD HTML 4.01 Transitional//ENquot;gt;
lt;htmlgt; lt;headgt; lt;titlegt;Testlt;/titlegt; lt;/headgt; lt;bodygt; lt;h1gt;#36827;#20837;LoginInput --gt; lt;a hrcf=quot;/loginInputquot;gt;LoinInputlt;/agt;lt;/h1gt; lt;/bodygt;
lt;/htmlgt;
LoginInput.jsp
HTML Code:
lt;%@ page language=quot;javaquot; import=quot;java.util.*quot; pageEncoding=quot;UTF-8quot;%gt;
lt;%@ taglib uri=quot;tagsquot; prefix=quot;springquot; %gt;
lt;%@ taglib uri=quot;tags/formquot; prefix=quot;springFormquot; %gt;
lt;!DOCTYPE HTML PUBLIC quot;-//W3C//DTD HTML 4.01 Transitional//ENquot;gt;
lt;htmlgt; lt;headgt; lt;titlegt;LoginInputlt;/titlegt; lt;/headgt; lt;bodygt; lt;springForm:form action=quot;/loginquot; commandName=quot;loginCommandquot;gt; lt;springForm:input path=quot;user.usernamequot; size=quot;10quot;/gt; lt;springForm:errors path=quot;user.usernamequot;/gt;lt;br/gt; lt;input type=quot;submitquot;/gt; lt;/springForm:formgt; lt;/bodygt;
lt;/htmlgt;I got the answer:
public String updateInput(....){ //database query //other operations return quot;/user/article/updateInput.jspquot;
}
public String update(....BindingResult result){ if(result.hasErrors()){ return updateInput(....); } //operations .....
} |
|