Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Spring form input binding problem

Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic