mike.tihonchik
Aug 31st, 2009, 04:23 PM
I am new to Spring MVC, and I can't seem to figure out what is the problem. I get the following exception: Neither BindingResult nor plain target object for bean name 'loginUser' available as request attribute. Here are my files: web.xml, ...-servlet.xml and LoginController.java
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<servlet>
<servlet-name>i550imports</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/i550imports-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>i550imports</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean name="loginController" class="controller.LoginController">
<property name="sessionForm" value="true" />
<property name="commandName" value="loginUser" />
<property name="commandClass" value="controller.LoginUser" />
<property name="formView" value="login" />
<property name="successView" value="transactions" />
</bean>
<bean name="transactionsController" class="controller.TransactionListController">
<property name="commandName" value="transactionSearchCriteria" />
<property name="commandClass" value="controller.TransactionSearchCriteria" />
<property name="formView" value="transactions" />
<property name="successView" value="transactions" />
<property name="transactionService" ref="transactionService" />
</bean>
<bean id="defaultHandler" class="org.springframework.web.servlet.mvc.Parameterizabl eViewController">
<property name="viewName" value="login" />
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<map>
<entry key="/login" value-ref="loginController" />
<entry key="/transactions" value-ref="transactionsController" />
</map>
</property>
<property name="defaultHandler" ref="defaultHandler"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewR esolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
package controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormCont roller;
public class LoginController extends SimpleFormController {
@Override
protected ModelAndView onSubmit(Object command) throws Exception {
LoginUser login = (LoginUser) command;
ModelAndView results = new ModelAndView(getSuccessView());
results.addObject("loginData", login);
return results;
}
}
I think, I messing up in the web.xml or ...-servlet.xml while defining my urlMapping, because if I change the following line to:
<entry key="/" value-ref="loginController" />
the login page come up. I also tried to something like this in web.xml:
<servlet-mapping>
<servlet-name>i550imports</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
but then I get following exception:
16:13:24,217 ERROR [[i550imports]] Servlet.service() for servlet i550imports threw exception
java.lang.StackOverflowError
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:210)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
Thank you in advance, any help would be appreciated.
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<servlet>
<servlet-name>i550imports</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/i550imports-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>i550imports</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean name="loginController" class="controller.LoginController">
<property name="sessionForm" value="true" />
<property name="commandName" value="loginUser" />
<property name="commandClass" value="controller.LoginUser" />
<property name="formView" value="login" />
<property name="successView" value="transactions" />
</bean>
<bean name="transactionsController" class="controller.TransactionListController">
<property name="commandName" value="transactionSearchCriteria" />
<property name="commandClass" value="controller.TransactionSearchCriteria" />
<property name="formView" value="transactions" />
<property name="successView" value="transactions" />
<property name="transactionService" ref="transactionService" />
</bean>
<bean id="defaultHandler" class="org.springframework.web.servlet.mvc.Parameterizabl eViewController">
<property name="viewName" value="login" />
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<map>
<entry key="/login" value-ref="loginController" />
<entry key="/transactions" value-ref="transactionsController" />
</map>
</property>
<property name="defaultHandler" ref="defaultHandler"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewR esolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
package controller;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormCont roller;
public class LoginController extends SimpleFormController {
@Override
protected ModelAndView onSubmit(Object command) throws Exception {
LoginUser login = (LoginUser) command;
ModelAndView results = new ModelAndView(getSuccessView());
results.addObject("loginData", login);
return results;
}
}
I think, I messing up in the web.xml or ...-servlet.xml while defining my urlMapping, because if I change the following line to:
<entry key="/" value-ref="loginController" />
the login page come up. I also tried to something like this in web.xml:
<servlet-mapping>
<servlet-name>i550imports</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
but then I get following exception:
16:13:24,217 ERROR [[i550imports]] Servlet.service() for servlet i550imports threw exception
java.lang.StackOverflowError
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:210)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.ge tAttribute(ApplicationHttpRequest.java:222)
Thank you in advance, any help would be appreciated.