Results 1 to 3 of 3
  1. #1
    bubbless is offline Member
    Join Date
    Mar 2009
    Posts
    81
    Rep Power
    0

    Default Neither BindingResult nor plain target object for bean name

    Hi,

    I get the infamous "java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'user' available as request attribute" error. I've googled it, alot, and it seems in 95% of the cases the developer forgot to add the modelAttribute in the form. However I did add it and I can't find out what's wrong.

    The first exception is "org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/register.jsp at line 8", maybe that adds something?

    Thanks in advance

    register.jsp
    Java Code:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@page session="true" %>
    
    <jsp:include page="header.jsp" />
    
    <form:form method="POST" action="registerProcessed" modelAttribute="user">
    <form:label path="username"></form:label><br />
    <form:input path="username"></form:input><br />
    <form:label path="password"></form:label><br />
    <form:password path="password"></form:password><br />
    <input type="submit" name="submit" value="Register" />
    </form:form>
    
    <jsp:include page="footer.jsp" />
    Leads to: registerProcessed
    Java Code:
    	@RequestMapping(value = "/registerProcessed", method = RequestMethod.POST)
    	public String registerProcessed(@ModelAttribute("user") User user, BindingResult result, Model model) {
    		model.addAttribute("title","Register processed");
    		model.addAttribute("username",user.getUsername());
    		
    		return "registerProcessed";
    	}
    Leads to: registerProcessed.jsp
    Java Code:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@page session="true" %>
    
    <jsp:include page="header.jsp" />
    
    Hai, ${username}
    
    <jsp:include page="footer.jsp" />
    User class
    Java Code:
    package be.mytravelmap.mytravelmap.domain;
    
    public class User {
    	private String username;
    	private String password;
    	
    	public String getUsername() {
    		return username;
    	}
    	public void setUsername(String username) {
    		this.username = username;
    	}
    	public String getPassword() {
    		return password;
    	}
    	public void setPassword(String password) {
    		this.password = password;
    	}
    }

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,824
    Rep Power
    19

    Default Re: Neither BindingResult nor plain target object for bean name

    That error says "register.jsp", which you haven't shown us.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    bubbless is offline Member
    Join Date
    Mar 2009
    Posts
    81
    Rep Power
    0

    Default Re: Neither BindingResult nor plain target object for bean name

    Quote Originally Posted by Tolls View Post
    That error says "register.jsp", which you haven't shown us.
    It's the first piece of code in the OP.

    Edit, made some JSTL mistakes, still have the bean error.

    Updated register.jsp:

    Java Code:
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@page session="true" %>
    
    <jsp:include page="header.jsp" />
    
    <form:form method="POST" action="/registerProcessed" modelAttribute="user">
    <form:label path="username">Username:</form:label><br />
    <form:input path="username" /><br />
    <form:label path="password">Password:</form:label><br />
    <form:password path="password" /><br />
    <input type="submit" name="submit" value="Register" />
    </form:form>
    
    <jsp:include page="footer.jsp" />
    Last edited by bubbless; 05-21-2013 at 11:09 AM.

Similar Threads

  1. Replies: 7
    Last Post: 09-26-2012, 01:32 PM
  2. Best way to access and display bean object data?
    By noodle_variation_187-X in forum JavaServer Pages (JSP) and JSTL
    Replies: 29
    Last Post: 06-21-2012, 02:46 PM
  3. Replies: 3
    Last Post: 06-08-2010, 08:10 PM
  4. Replies: 1
    Last Post: 01-29-2009, 09:35 AM
  5. Replies: 1
    Last Post: 01-29-2009, 09:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •