我试图在Tomcat 8.0 Server上使用Spring Framework开发Web应用程序但是,我坚持这个错误。其他两个表单页面能够使用ModelAttribute绑定表单中的数据,但是第三个是userprofile.jsp,它会抛出错误" 既不是BindingResult,也不是bean名称的普通目标对象& #39; setupuser'可用作请求属性 "。请帮助我摆脱这个错误。谢谢
错误 -
Jan 18, 2016 4:32:12 PM org.springframework.web.servlet.tags.form.InputTag doStartTag
SEVERE: Neither BindingResult nor plain target object for bean name 'setupuser' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'setupuser' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:165)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:152)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:143)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.views.userprofile_jsp._jspx_meth_form_005finput_005f0(userprofile_jsp.java:386)
at org.apache.jsp.WEB_002dINF.views.userprofile_jsp._jspService(userprofile_jsp.java:168)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:719)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:465)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:390)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:317)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1201)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Jan 18, 2016 4:32:12 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'setupuser' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:165)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:152)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:143)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.views.userprofile_jsp._jspx_meth_form_005finput_005f0(userprofile_jsp.java:386)
at org.apache.jsp.WEB_002dINF.views.userprofile_jsp._jspService(userprofile_jsp.java:168)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:719)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:465)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:390)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:317)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1201)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Jan 18, 2016 4:32:12 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [onlineEnrollment] in context with path [/onlineEnrollment] threw exception [An exception occurred processing JSP page /WEB-INF/views/userprofile.jsp at line 17
14: <b>Setup your contact information:</b> <br />
15:
16: <form:form method="POST" modelAttribute="setupuser">
17: EMAIL ADDRESS: <form:input path="email" /> <br />
18: <form:errors path="email" cssStyle="" cssClass="color:red;" /><br />
19: CONFIRM EMAIL ADDRESS: <form:input path="confirmEmail" /> <br />
20: <form:errors path="confirmEmail" cssClass="color:red;" /><br /><br />
Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'setupuser' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:179)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:199)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:165)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:152)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:143)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:103)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.views.userprofile_jsp._jspx_meth_form_005finput_005f0(userprofile_jsp.java:386)
at org.apache.jsp.WEB_002dINF.views.userprofile_jsp._jspService(userprofile_jsp.java:168)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:719)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:465)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:390)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:317)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1201)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:986)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
OptionalServicesController.java -
package com.banking.onlineenrollment.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.banking.onlineenrollment.service.UserService;
import com.banking.onlineenrollment.user.UserAgreementForm;
@Controller
@RequestMapping(value = "/optional.do")
public class OptionalServicesController {
private UserService userService;
@Autowired
public OptionalServicesController(UserService userService) {
// TODO Auto-generated constructor stub
this.userService = userService;
}
@RequestMapping(method = RequestMethod.GET)
public ModelAndView displayOptionalServices() {
ModelAndView mv = new ModelAndView("optionalservices");
UserAgreementForm userAgreementForm = new UserAgreementForm();
mv.addObject("optionalservices", userAgreementForm);
return mv;
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processOptionalServices(@ModelAttribute("optionalservices") UserAgreementForm userAgreementForm) {
ModelAndView mv = new ModelAndView();
userService.saveOptionalServices(userAgreementForm.getEnrollServices(), userAgreementForm.getVerifyServices());
mv.setViewName("userprofile");
return mv;
}
}
userprofile.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Setup User Profile</title>
</head>
<body>
<h3>4.Setup User Profile</h3>
The following is required to complete your user profile.<br /><c:out value="${message}"></c:out><br /><br />
<b>Setup your contact information:</b> <br />
<form:form method="POST" modelAttribute="setupuser">
EMAIL ADDRESS: <form:input path="email" /> <br />
<form:errors path="email" cssStyle="" cssClass="color:red;" /><br />
CONFIRM EMAIL ADDRESS: <form:input path="confirmEmail" /> <br />
<form:errors path="confirmEmail" cssClass="color:red;" /><br /><br />
<b>Setup your username and password:</b><br />
USERNAME: <form:input path="username" /> <br />
<form:errors path="username" cssClass="color:red;" /><br />
PASSWORD: <form:password path="password" /> <br />
<form:errors path="password" cssClass="color:red;" /><br />
CONFIRM PASSWORD: <form:password path="confirmPassword" /> <br />
<form:errors path="confirmPassword" cssClass="color:red;" /><br />
<input type="submit" value="Continue"> <br /><br />
Password Complexity Requirements
Your password cannot contain your username.
Your password must be a minimum of 8 characters and must
meet at least 3 of the following 4 categories:
English uppercase characters (A - Z)
English lowercase characters (a - z)
Numeric digits (0 - 9)
Non-alphanumeric (For example: !, $, #, or %)
Passwords are case sensitive. For added security we
recommend that you change your password every 90 days.
</form:form>
</body>
</html>
UserProfileController.java
/**
*
*/
package com.banking.onlineenrollment.controller;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.banking.onlineenrollment.service.UserService;
import com.banking.onlineenrollment.user.UserProfileForm;
/**
* @author Harsh
*
*/
@Controller
@RequestMapping(value = "/userprofile.do")
public class UserProfileController {
private UserService userService;
@Autowired
public UserProfileController(UserService userService) {
// TODO Auto-generated constructor stub
this.userService = userService;
}
@RequestMapping(method = RequestMethod.GET)
public ModelAndView displayUserProfile() {
ModelAndView mv = new ModelAndView("userprofile");
UserProfileForm userProfileForm = new UserProfileForm();
mv.addObject("setupuser", userProfileForm);
return mv;
}
@RequestMapping(method = RequestMethod.POST)
public ModelAndView processUserProfile(@Valid @ModelAttribute("setupuser") UserProfileForm userProfileForm, BindingResult result) {
System.out.println("Inside POST method beginning of userprofile");
ModelAndView mv = new ModelAndView();
if(result.hasErrors()) {
mv.setViewName("userprofile");
mv.addObject("message", "Don't leave the form blank");
}
else {
userService.saveUserProfile(userProfileForm.getEmail(),userProfileForm.getConfirmEmail(),userProfileForm.getUsername(),userProfileForm.getPassword(), userProfileForm.getConfirmPassword());
mv.setViewName("securityprofile");
}
return mv;
}
}
UserService.java
package com.banking.onlineenrollment.service;
/**
* @author Harsh
*
*/
public interface UserService {
public int isValid(String idType, int idNum, String token);
public void saveOptionalServices(int enrollServices, int verifyServices);
public void saveUserProfile(String email, String confirmEmail, String username, String password, String confirmPassword);
public void saveSecurityProfile(int q1, String a1, int q2, String a2,
int q3, String a3, int q4, String a4 );
}
UserAgreementForm.java
package com.banking.onlineenrollment.user;
import org.springframework.stereotype.Component;
@Component
public class UserAgreementForm {
private int enrollServices;
private int verifyServices;
public int getEnrollServices() {
return enrollServices;
}
public void setEnrollServices(int enrollServices) {
this.enrollServices = enrollServices;
}
public int getVerifyServices() {
return verifyServices;
}
public void setVerifyServices(int verifyServices) {
this.verifyServices = verifyServices;
}
}
Web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>onlineEnrollment</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>onlineEnrollment</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>onlineEnrollment</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
UserProfileForm
/**
*
*/
package com.banking.onlineenrollment.user;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.stereotype.Component;
/**
* @author Harsh
*
*/
@Component
public class UserProfileForm {
@NotBlank
@Size(min = 5, max = 20)
@Email
private String email;
@NotBlank
@Size(min = 5, max = 20)
@Email
private String confirmEmail;
@NotBlank
@Size(min = 5, max = 20)
private String username;
@NotBlank
private String password;
@NotBlank
private String confirmPassword;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getConfirmEmail() {
return confirmEmail;
}
public void setConfirmEmail(String confirmEmail) {
this.confirmEmail = confirmEmail;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getConfirmPassword() {
return confirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
}
答案 0 :(得分:0)
您可以尝试在功能级别而不是类级别上注释请求映射:
但首先添加
<mvc:annotation-driven />
到 onlineEnrollment-servlet.xml
xmlns:mvc="http://www.springframework.org/schema/mvc"
中的<{1}}声明以及<beans ...>
现在尝试将控制器方法(只是完全复制到您的代码)更改为:
onlineEnrollment-servlet.xml
现在将 package com.banking.onlineenrollment.controller;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.banking.onlineenrollment.service.UserService;
import com.banking.onlineenrollment.user.UserProfileForm;
/**
* @author Harsh
*
*/
@Controller
// @RequestMapping(value = "/userprofile.do")
public class UserProfileController {
private UserService userService;
@Autowired
public UserProfileController(UserService userService) {
// TODO Auto-generated constructor stub
this.userService = userService;
}
@RequestMapping(value="/askform.do",method = RequestMethod.GET)
public ModelAndView displayUserProfile() {
ModelAndView mv = new ModelAndView("userprofile");
UserProfileForm userProfileForm = new UserProfileForm();
mv.addObject("setupuser", userProfileForm);
return mv;
}
@RequestMapping(value="/populateformfield.do",method = RequestMethod.POST)
public ModelAndView processUserProfile(@Valid @ModelAttribute("setupuser") UserProfileForm userProfileForm, BindingResult result) {
System.out.println("Inside POST method beginning of userprofile");
ModelAndView mv = new ModelAndView();
if(result.hasErrors()) {
mv.setViewName("userprofile");
mv.addObject("message", "Don't leave the form blank");
}
else {
userService.saveUserProfile(userProfileForm.getEmail(),userProfileForm.getConfirmEmail(),userProfileForm.getUsername(),userProfileForm.getPassword(), userProfileForm.getConfirmPassword());
mv.setViewName("securityprofile");
}
return mv;
}
}
更改为:
userProfile.jsp
现在请求表单<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Setup User Profile</title>
</head>
<body>
<h3>4.Setup User Profile</h3>
The following is required to complete your user profile.<br /><c:out value="${message}"></c:out><br /><br />
<b>Setup your contact information:</b> <br />
<form:form method="POST" modelAttribute="setupuser" action="populateformfield.do">
EMAIL ADDRESS: <form:input path="email" /> <br />
<form:errors path="email" cssStyle="" cssClass="color:red;" /><br />
CONFIRM EMAIL ADDRESS: <form:input path="confirmEmail" /> <br />
<form:errors path="confirmEmail" cssClass="color:red;" /><br /><br />
<b>Setup your username and password:</b><br />
USERNAME: <form:input path="username" /> <br />
<form:errors path="username" cssClass="color:red;" /><br />
PASSWORD: <form:password path="password" /> <br />
<form:errors path="password" cssClass="color:red;" /><br />
CONFIRM PASSWORD: <form:password path="confirmPassword" /> <br />
<form:errors path="confirmPassword" cssClass="color:red;" /><br />
<input type="submit" value="Continue"> <br /><br />
Password Complexity Requirements
Your password cannot contain your username.
Your password must be a minimum of 8 characters and must
meet at least 3 of the following 4 categories:
English uppercase characters (A - Z)
English lowercase characters (a - z)
Numeric digits (0 - 9)
Non-alphanumeric (For example: !, $, #, or %)
Passwords are case sensitive. For added security we
recommend that you change your password every 90 days.
</form:form>
</body>
</html>