Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Java Spring - IllegalStateException when retrieving data from jsp form

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have a pretty nasty and frustrating problem with a Maven Web Application, holding me back for some time.
Apparently, from my previous google searches, this is a common Spring MVC error, but i am not able to find the solution i need among the ones offered on the internet so far. Note that i am a beginner in Spring and in MVC concepts in general.

I have a web application which is supposed to manage a building administration (inhabitants, rent calculations, etc). I use Spring MVC, Hibernate, Java 1.8, Tomcat 8 server container, and SQL Server 2014.
Firstly, this is my POJO for the bulding residents, a type called Inhabitant:



This is my dispatcher-servlet.xml:



This is my web.xml:


This is my jsp registration form, which should map to the Inhabitant object:


And finally, the controller class, which should effectively map the data from the jsp form with the java entity, Inhabitant:



Now, this is the error i get whenever i try to run my application on the server:

message java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'inhabitant' available as request attribute

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'inhabitant' available as request attribute
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'inhabitant' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:117)
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
org.apache.jsp.login.index_jsp._jspx_meth_form_005finput_005f0(index_jsp.java:322)
org.apache.jsp.login.index_jsp._jspx_meth_form_005fform_005f0(index_jsp.java:216)
org.apache.jsp.login.index_jsp._jspService(index_jsp.java:148)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


I have tried a thousand things, but i just can't get it to work. So, please, can someone point out what i'm doing wrong? How can i correctly build the java object based on the information from the jsp form?

Thanks in advance!
 
A Misa
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helloa again! Any idea, anyone?
 
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pattern you are using is not really correct.  Here is an example controller.



Here is an example jsp being used along with it, that displays and submits to the same bean.  Notice that in the example, the field is actually inside another value object inside of the bean.    This is just to show that any level of VO embedding can be done.  I like JSTL better than the Spring tags.

viewUserProfile.jsp



You don't need to use ModelMap.  I just use that for getting stuff out of session.  Your params will land in that first param in the controller which will live only as long as the request.  You have no need for the session unless you want something to persist longer.  In that case you need to annotate a bean as being session scoped up above the controller.
 
Matt Keller
Ranch Hand
Posts: 32
1
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, as far as I know, you don't need any of those annotations on the bean.
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic