I am getting the following exception while implementing a spring mvc program with form handling. Could you help me with this?
Stacktrace of the exception is as follows:
Dec 30, 2013 11:50:28 PM org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag
SEVERE: Neither BindingResult nor plain target object for bean name 'login' available as request attribute
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'login' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:117)
at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at org.apache.jsp.WEB_002dINF.pages.login_jsp._jspx_meth_form_005finput_005f0(login_jsp.java:187)
at org.apache.jsp.WEB_002dINF.pages.login_jsp._jspx_meth_form_005fform_005f0(login_jsp.java:133)
at org.apache.jsp.WEB_002dINF.pages.login_jsp._jspService(login_jsp.java:88)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Login.jsp - This is the jsp file that throws the exception
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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>Chronos Login</title>
<link href="/chronos/resources/css/main.css" rel="stylesheet" type="text/css" media="screen">
<script>
function submitOnClick(formName){
document.forms[formName].submit();
}
</script>
</head>
<body>
<form:form id="loginForm" method="POST" action="login.html" modelAttribute="login">
<div id="container">
<div id = "left">
<div id="row">
<label for="username">Username:</label>
<form:input type="text" id="username" path="username"/>
</div>
<div id="row">
<label for="password">Password:</label>
<form:input type="password" id="password" path="password" />
</div>
<div id="message"></div>
</div>
<div id="submit" onClick="submitOnClick('loginForm')">
<!--<input type="submit" value=">">-->
<div id="arrow">></div>
</div>
<div class="clear"></div>
</div>
</form:form>
</body>
</html>
BaseController.java - the controller class, that simply prints the user name and password when login.jsp
is submitted
package com.chronos.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
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.chronos.beans.LoginBean;
@Controller
@RequestMapping("login.html")
public class BaseController {
@RequestMapping(method = RequestMethod.GET)
public String login(Model model) {
System.out.println("here");
model.addAttribute("login", new LoginBean());
return "login";
}
@RequestMapping(method = RequestMethod.POST)
public String loginValidate(@ModelAttribute("login")LoginBean loginBean, ModelMap model) {
System.out.println(loginBean.getUsername());
System.out.println(loginBean.getPassword());
return "success";
}
}
Thanks for your help in advance.
Here , you have to replace as below ,
@ModelAttribute("login")LoginBean loginBean
To
@ModelAttribute("LoginBean")LoginBean loginBean
This will work fine.......