Spring Controller(SimpleFormController)出错

时间:2014-08-25 22:14:42

标签: spring spring-mvc

当我使用SimpleFormController时,我正在使用Spring 4.0框架我的代码中出现错误。任何人都可以帮助我吗?

        package sample;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.ServletException;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.view.RedirectView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    import sample.login;

    @SuppressWarnings("deprecation")
    public class LoginFormController extends SimpleFormController//Error here cannot resolve the controller
    { 
        protected ModelAndView onSubmit(Object command) throws ServletException
        {
            login login = (login) command;
            String name = login.getUsername();
            String prestatement = "Hello";
            ModelAndView modelAndView = new ModelAndView();
            modelAndView.addObject("name", name);
            return modelAndView;
            }

}

我在我的项目中添加了库文件?我的调度程序文件如下

    <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"
  xmlns:p="http://www.springframework.org/schema/p
  http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <bean id="viewResolver" 
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
           <property name="prefix"> 
           <value>/WEB-INF/jsp/</value>
            </property>

            <property name="suffix">
                <value>index.jsp</value>
            </property>
  </bean> 

  <bean id="urlMapping" 
       class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 

       <property name="interceptors"> 
       <list><ref local="localeChangeInterceptor"/></list>
       </property>

       <property name="urlMap">
         <map> 
         <entry key="/login.html"><ref bean="loginController"/> </entry>
         </map> 
        </property>
   </bean>

         <bean id="loginValidator"
            class="sample.LoginValidator"/>


            <bean id="loginController" class="sample.LoginFormController"> 

                <property name="sessionForm">
                <value>false</value></property> 

                <property name="commandName">
                <value>login</value></property> 

                <property name="commandClass">
                <value>sample.Login</value>

                </property> <property name="validator">
                <ref bean="loginValidator"/></property>
                <property name="formView"><value>login</value></property> 

                <property name="successView">
                <value>success</value>
                </property>

            </bean> 

            <bean id="localeChangeInterceptor" 
              class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
               <property name="paramName" value="hl"/>
            </bean>

            <bean id="localeResolver"
                class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>
</beans>    

1 个答案:

答案 0 :(得分:1)

截至Spring 3.0,

SimpleFormController已被弃用。我认为这个类已经在4.0版本中删除了。首选方法是使用注释。