jQuery in Action, 2nd edition*
The moose likes Other Application Frameworks and the fly likes Spring form input binding problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring form input binding problem" Watch "Spring form input binding problem" New topic

Spring form input binding problem

Ramesh kangamuthu
Ranch Hand

Joined: Mar 13, 2007
Posts: 79
Hi Everyone,

I am new to Spring. I tried to execute a simple user login program. I got the following error

Neither BindingResult nor plain target object for bean name 'user' available as request attribute

My code is as follows


<%@ include file="taglibs.jsp" %>
<%@ include file="header.jsp" %>

<body bgcolor="lightblue" text="yellow">
<%--<form:form commandName="user" action="/loginUser.htm" method="post">
<form:errors path="user"/>
<form:input path="username"/><br>
<script type="text/javascript">document.getElementById("username").focus();</script>
<form assword path="password"/><br>
<input type="submit" value="Submit"/>
<form:form action="/loginUser.htm" method="post" commandName="user">
<spring:bind path="username">
<input type="text" name='<c ut value="${status.expression}"/>' value='<c ut value="${status.value}"/>'><br>
<spring:bind path="password">
<input type="text" name='<c ut value="${status.expression}"/>' value='<c ut value="${status.value}"/>'><br>
<spring:hasBindErrors name="user">
<font color="red"><c ut value="${status.errorMessage}"/></font>
<%--<spring:hasBindErrors name="user.password">
<font color="red"><c ut value="${status.errorMessage}"/></font>
<input type="submit" value="Login"/>


* To change this template, choose Tools | Templates
* and open the template in the editor.

package controllers;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.bind.RequestUtils;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import services.LoginService;
import users.User;
import validators.LoginValidator;

* @author ramesh.k

// This class is a Controller that handles all Spring MVC web requests
public class LoginController extends SimpleFormController{

public LoginController(){
//This method set the type of class for the Command Object
System.out.println("commandName,formView,successView,sessionForm properties were set");

//declaration of login service bean
private LoginService loginService;

//declaration of login validator
private LoginValidator validator;

/*public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response){
LoginService service=new LoginService();
ModelAndView authentication_data=service.authenticate(request.getParameter("username"),request.getParameter("password"));

return authentication_data;

/* @Override
protected Object formBackingObject(HttpServletRequest request) throws ServletRequestBindingException {
System.out.println("Username is "+RequestUtils.getStringParameter(request,"username"));
User user=new User();
return user;

/* @Override
protected ModelAndView showForm(HttpServletRequest request,HttpServletResponse response,BindException errors){
System.out.println("Form is shown");
String viewName=null;
System.out.println("Form input has error");
System.out.println("Form input is correct");
return new ModelAndView(viewName);

// A method is used to do display of a form and a form submit.
protected ModelAndView onSubmit(Object command) throws Exception{
System.out.println("hello ");
loginService=new LoginService();
User user=(User)command;
System.out.println("welcome "+user.getUsername());
/* ModelAndView view_data=null;

return getLoginService().authenticate(user);


//getters and setters of loginService property
public LoginService getLoginService() {
return loginService;

public void setLoginService(LoginService loginService) {
this.loginService = loginService;

// object of this class is a property of a LoginController class

* To change this template, choose Tools | Templates
* and open the template in the editor.

package services;

import org.springframework.web.servlet.ModelAndView;
import users.User;

* @author ramesh.k

//This class is responsible for doing business logic for the login operation
public class LoginService {

public LoginService(){


//This method authenticates the User retrieved by the values entered in the form
public ModelAndView authenticate(User user){
ModelAndView view_data=null;
System.out.println("Inside the method authenticate()");
view_data=new ModelAndView("success");
view_data=new ModelAndView("login");
return view_data;

When I submit the form, The above mentioned error comes. please help me to solve this.

Thanks and regards,

Ramesh K
subject: Spring form input binding problem
Similar Threads
que in spring mvc - simpleformcontroller
spring mvc problem while doing Validation
how to tell MultiActionController Command Object is Of type com.dss.ems.model.User
using SimpleFormController
display exception on formbackingobject