I’m just new to Spring, stuck up with some error past two days. Would like somebody to help and solve the problem. Also I googled the error but could not understand the root cause of the error. I've not studied about the annotations in spring yet, so could not understand most of the examples online.
Error occured in the program:
java.lang.IllegalStateException
: NeitherBindingResult
nor plain target object for bean name 'login
' available as request attribute
Here, is the code of the application:
data.jsp:(This is a view page to accept the data from the user)
<form:form commandName="login" method="POST" name="login">
Username:<form:input path="name"/>
<font color="red"><form:errors path="name"/></font><br/><br/>
<input type="submit" value="Login"/>
</form:form>
LoginFormController.java:(Controller page to process the request)
package Controller;
import model.Student;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
public class LoginFormController extends SimpleFormController {
public LoginFormController() {
//Initialize controller properties here or
//in the Web Application Context
setCommandClass(Student.class);
setCommandName("login");
setSuccessView("success");
setFormView("data");
}
@Override
protected ModelAndView onSubmit(Object command) throws Exception {
Student s1= (Student)command;
ModelAndView mv = new ModelAndView(getSuccessView());
mv.addObject("message", "Hello! "+s1.getName());
return mv;
}
}
Student.java:(java model class)
package model;
public class Student {
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Student() {
}
public Student(String name) {
this.name = name;
}
}
dispatcher-servlet.xml:(xml file description)
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
<prop key="data.htm">dataController</prop>
<prop key="/login.htm">loginDataController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean name="dataController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="data" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="Student" class="model.Student"/>
<bean id="loginDataController" class="Controller.LoginFormController"/>
Can anyone provide help finding a solution?