Hello,
first of all, sorry about my english
I have create two *.jsp files.
In the first .jsp file (index.jsp) you can enter your name.
HTML Code:... <html> <head> <title>index.jsp</title> </head> <body> <form action="/spring/index.html" method="POST"> insert your name<br /> <input type="text" name="username"></input> <input type="submit" value="send" /> </form> </body> </html>
The second .jsp file (output.jsp) should display the entered name.
HTML Code:... <html> <head> <title>title</title> </head> <body> Hello <c:out value="${Person.name}"></c:out> ! </body> </html>
After pressing the submit button, i get the following error message.
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/index.html' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Cannot resolve reference to bean 'person' while setting bean property 'person'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'person' is defined
spring-servlet.xml
Code:... <bean name="/index.html" class="org.spring.FrontController" > <property name="formView" value="index" /> <property name="successView" value="output" /> <property name="person" ref="person" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> ...
FrontController.java
Code:package org.spring; import javax.servlet.ServletException; import javax.servlet.h..p.H..pServletRequest; import javax.servlet.h..p.H..pServletResponse; import org.springframework.validation.BindException; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; public class FrontController extends SimpleFormController { public FrontController() { setCommandClass(PersonBean.class); setCommandName("person"); } protected Object formBackingObject(HttpServletRequest request) throws ServletException { Object formBackingObject = null; try { formBackingObject = super.formBackingObject(request); } catch (Exception e) { e.printStackTrace(); } return formBackingObject; } protected Object referenceData(HttpServletResponse response) throws ServletException { return logger; } protected ModelAndView onSubmit(Object command, BindException bindException) throws Exception { PersonBean person = (PersonBean) command; System.out.println("username: " + person.getUsername()); // return new ModelAndView("output", "person", person); System.out.println("view: " + getSuccessView()); return new ModelAndView(getSuccessView()); } }
PersonBean.java
Code:package org.spring; public class PersonBean { private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } }
How can i fix the bug ?
Thanks
Angelika



Reply With Quote