This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BindingResult nor plain target object for bean name 'usersuccess' available as request attribute"

 
shyampriya soni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello....
I am trying to develop web application using spring mvc framework which contain 2 form.
1. user form 2. usersuccess form
i am using 2 controllers for these two forms. i am able to disblay my first form but when i click on submit button on user form i got following error
"java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'usersuccess' available as request attribute"

please help

my code:

User.java

ackage com.vaannila.domain;

public class User {

private String name;
private String password;


public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}


UserSuccess.java


package com.vaannila.domain;

public class UserSuccess {

protected String amtinfo;
protected String amtwithdraw;


public String getAmtInfo() {
return amtinfo;
}
public void setAmtInfo(String amtinfo) {
this.amtinfo = amtinfo;
}
public String getAmtWithdraw() {
return amtwithdraw;
}
public void setAmtWithdraw(String amtwithdraw) {
this.amtwithdraw = amtwithdraw;
}
}

UserController.java
package com.vaannila.web;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.vaannila.domain.User;


@SuppressWarnings("deprecation")
public class UserController extends SimpleFormController {


User user = new User();
public UserController() {
setCommandClass(User.class);
setCommandName("user");
}


@Override
protected ModelAndView onSubmit(Object command) throws Exception {
User user = (User) command;
return new ModelAndView("userSuccess","user",user);
}

}

UserSuccesController.java

package com.vaannila.web;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;


import com.vaannila.domain.UserSuccess;


@SuppressWarnings("deprecation")
public class UserSuccessController extends SimpleFormController {



UserSuccess usersuccess = new UserSuccess();
public UserSuccessController(){
setCommandClass(UserSuccess.class);
setCommandName("usersuccess");
}

@Override
public ModelAndView onSubmit(Object commandName) throws Exception {
UserSuccess usersuccess = (UserSuccess) commandName;
return new ModelAndView("logout","usersuccess",usersuccess);
}

}

dispactcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />

<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
p:basename="/WEB-INF/messages" />

<bean id="userValidator"
class="com.vaannila.validator.UserValidator" />

<bean name="/userRegistration.htm"
class = "com.vaannila.web.UserController"
p:formView = "userForm" p:successView="userSuccess" p:validator-ref="userValidator" />

<bean name="/usersuccesss.htm" class="com.vaannila.web.UserSuccessController">
<property name="commandName" value="usersuccess"/>
<property name="commandClass" value="com.vaannila.domain.UserSuccess"/>
<property name="formView" value="userSuccess"/>
<property name="successView" value="logout"/>
</bean>

</beans>















 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the CODE tags when posting code and configuration. I can't read the code without the indentations.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you are just learning Spring and Spring MVC, I recommend using material that is up to date.

public class UserController extends SimpleFormController

extending or implementing any Spring Controller class or Interface is not recommended for at least the past 5 years, and are actually now deprecated.

It is much easier and better to use Annotations and current Spring MVC.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic