Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Spring 3.1 MVC -- Neither BindingResult nor plain target object for bean name available as request

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a Spring MVC newbie, and I am trying to call up a JSP in my Spring 3.1 MVC application, and I'm getting an error message instead. Can anyone help me? Here is the error message when I call up GuestBook.jsp.



Here is GuestBook.jsp.


This is web.xml


This is applicationContext.xml.


This is ghs1986-servlet.xml


This is com.controller.CommentController.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, you have some old style stuff, some new stuff and neither is connected to each other.

First you have

<mvc:annotation-driven />
<context:component-scan base-package="com.controller" />

in your applicationContext.xml. But they should be in your ghs1986-servlet.xml

That -servlet.xml is for all your Web Layer beans, including your Controllers.

You should not be declaring your controller as a <bean> since your Controller has all the annotations in it and mvc:annotation-driven will find all of them and map your URLs to your controller methods via the @RequestMapping annotations.

in the applicationContext.xml should be all your beans that are in your middle tier. The business layers and daos.

Check out this thread from this past week to explain applicationContext.xml versus xxxxx-servlet.xml
https://coderanch.com/t/586814/Spring/Conflict-mvc-annotation-driven

Mark
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I move <mvc:annotation-driven /> to ghs1986-servlet.xml, I get a message from Eclipse that says, "The prefix 'mvc' for element 'mvc:annotation-driven' is not bound." How do I fix that?
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to add the mvc namespace to the top of the xml file. You can look at your other configuration file for an example. Also STS will do this for you if you open it with the spring editor there is a namespaces tab, where you can just add the mvc namespace.


Also as Mark already stated you should not be creating the Comment controller bean at all but on top of that you are injecting a Comment bean. This is a Singleton, I assume you don't want every request sharing the same comment.

You should also remove this block of code from your controller


Once you get through all of the fixes you have been suggested so far we can start debugging your other issue. That error generally means that the binding result is not immediately following a method attribute in the paramter list or you are trying to access a property on the method attribute in your jsp improperly or other times it does not exist at all (or is mispelled)
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just moved the mvc line as well as the context:component line over, but now both lines are giving me basically the same error:

 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why in one you havespring-beans-3.0.xsd and in the other you have spring-beans-2.0.xsd? Hopefully you do not have multiple versions of Spring on the classpath as well.

replace whatever you have at the top of the servlet xml with what you have at the top of your application.xml

i.e.

 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I have fixed the schemaLocation error. I guess I need to stop cutting and pasting from tutorials without reading them first. I still have the original problem, though.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you can re-post what you have so we are looking at the latest after you have made the suggested corrections.
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Error in browser window:


GuestBook.jsp


CommentController.java


applicationContext.xml


ghs1986-servlet.xml
 
Frank Serkland
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to review the basics of Spring and then come back to this problem another time. Thanks to all who tried to help me, and my apologies to whoever comes across this thread looking for help.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Controller
@RequestMapping("/GuestBook.jsp")
@SessionAttributes("comment")
public class CommentController extends SimpleFormController {

Looking at this you are trying to use two totally different Spring MVC approaches. One the old style where you extend a Controller class and the newer style of using annotations. I'd stick with annotations.

Also,

<bean name="comment" class="com.model.Comment" />

domain objects and stateful objects are never defined as beans.

Mark
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic