Hi All,
I am new to spring , i am trying an example in spring MVC, but i am getting the mentioned error ,please check my code and help me to resolve the issue.
I tried in different URL mappings (like beanNameUrlMapping ,simpleUrlMapping ) but unable to resolve the issue, please let me know root cause for this issue and steps to resolve the issue
Thanks in Advance
My code
In this example i am just entering registration details in a
jSP and want to show the details in once user details once registration is done.
Register.jsp
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>Spring 3 MVC Series - Contact Manager</title>
</head>
<body>
<form:form method="post" action="addContact.html" commandName="User" >
<table>
<tr>
<td><form:label path="firstname">First Name</form:label></td>
<td><form:input path="firstname" /></td>
</tr>
<tr>
<td><form:label path="lastname">Last Name</form:label></td>
<td><form:input path="lastname" /></td>
</tr>
<tr>
<td><form:label path="email">Email</form:label></td>
<td><form:input path="email" /></td>
</tr>
<tr>
<td><form:label path="telephone">Telephone</form:label></td>
<td><form:input path="telephone" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Add Contact"/>
</td>
</tr>
</table>
</form:form>
</body>
</html>
config.xml file
<?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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.mys" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="userService" class="com.mys.services.UserServiceImpl" />
<bean name="/addContact.html" class="com.mys.login.RegistrationController"
p:userService-ref="userService" p:formView="Register" p:successView="success" />
</beans>
My controller class
import com.formbean.User;
import com.mys.services.UserService;
@SuppressWarnings("deprecation")
public class RegistrationController extends SimpleFormController {
private UserService userService;
public RegistrationController() {
setCommandClass(User.class);
setCommandName("User");
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@Override
protected ModelAndView onSubmit(Object command) throws Exception {
User user = (User) command;
userService.add(user);
return new ModelAndView("success", "user", user);
}
}
Form bean User.java
package com.formbean;
public class User {
private
String firstname;
private String lastname;
private String email;
private String telephone;
//setters , getter ()
}
package com.mys.services;
import com.formbean.User;
public class UserServiceImpl implements UserService {
@Override
public void add(User user) {
// TODO Auto-generated method stub
System.out.println("user added successfully");
}
}
SEVERE: Neither BindingResult nor plain target object for bean name 'User' available as request attribute java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'User' available as request attribute at org.springframework.web.servlet.support.BindStatus.(BindStatus.java:141) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174) at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194) at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129) at org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119) at org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89) at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102) at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) at org.apache.jsp.Register_jsp._jspx_meth_form_005flabel_005f0(Register_jsp.java:188) at org.apache.jsp.Register_jsp._jspx_meth_form_005fform_005f0(Register_jsp.java:112) at org.apache.jsp.Register_jsp._jspService(Register_jsp.java:71) at