0
我的小項目存在問題。無論是BindingResult還是bean名稱spring的普通目標對象mvc
這裏是我的CONTROLER
@Controller
@RequestMapping("/loginPage")
public class LoginController
{
private static final String VN_LOGIN_FORM = "login/LoginForm";
private static final String VN_HOME_FORM = "redirect:../home.html";
String VN_LOGIN_FAIL_FROM = "redirect:../loginPage /login.html";
// @Autowired
private AccountService act;
private EmployeeService em;
@RequestMapping(value = "login", method = RequestMethod.GET)
public String getRegistrationForm(Model model)
{
model.addAttribute("user", new AccountForm());
return VN_LOGIN_FORM;
}
@RequestMapping(value = "", method = RequestMethod.POST)
public String postRegistrationForm(@ModelAttribute("user") AccountForm form)
{
Account temp = toAccount(form);
Account found = act.getAccount(temp.getUsername());
java.util.List<Employee> list = em.getNewEmployees();
if (found != null && found.getPassword().equals(temp.getPassword()))
{
return VN_HOME_FORM;
}
return VN_LOGIN_FAIL_FROM;
}
@InitBinder
public void initBinder(WebDataBinder binder)
{
binder.setAllowedFields(new String[ ] { "username", "password", "confirmPassword", "firstName", "lastName", "email",
"marketingOk", "acceptTerms" });
}
private static Account toAccount(AccountForm form)
{
Account account = new Account();
account.setUsername(form.getUsername());
account.setPassword(form.getPassword());
return account;
}
}
這是我的JPS頁面。
<form:form action="." modelAttribute="user" method="POST"
class="login">
<form:errors path="*">
<div class="warning alert">
<spring:message code="error.global" />
</div>
</form:errors>
<div>
<label for="username">${username}</label>
<form:input name="username" id="login" path="username"
cssErrorClass="short error" value="username" />
</div>
<br>
<div>
<label for="password">${password}</label>
<form:password path="password" name="password" value="1111111111" />
</div>
<div class="login-submit">
<button type="submit" value="" class="login-button">Submit</button>
</div>
<br>
<div class="forgot-password">
<button type="submit" class="btn-reset">Forgot your
password?</button>
<button type="submit" class="btn-reset">Reset</button>
</div>
</form:form>
這裏是異常跟蹤:
09:31:49,069 ERROR [org.springframework.web.servlet.tags.form.InputTag] (http-localhost-127.0.0.1-8080-1) Neither BindingResult nor plain target object for bean name 'user' available as request attribute: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:127) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.apache.jsp.WEB_002dINF.views.login.LoginForm_jsp._jspx_meth_form_005finput_005f0(LoginForm_jsp.java:364)
at org.apache.jsp.WEB_002dINF.views.login.LoginForm_jsp._jspService(LoginForm_jsp.java:174)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1157) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:927) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
這裏是我的信息豆-web.xml中
<mvc:view-controller path="/loginPage/login.html" view-name="login/LoginForm" />
我如何訪問這些頁面:
http://localhost:8080/spring-mvc/loginPage/login.html
我不明白問題在哪裏。
這可能是有用的,你 http://stackoverflow.com/questions/16787938/spring-mvc-neither-bindingresult-nor-plain-target-object-for-bean-name – 2015-04-03 06:43:15
可能重複http://stackoverflow.com/questions/29003809/java-lang-illegalstateexception-neither-bindingresult-nor-plain-target-object-f – OO7 2015-04-03 06:59:00