Java中的SimpleFormController问题

时间:2015-06-08 06:29:18

标签: java spring-mvc

我需要知道如下所示的错误:

package com.ht.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

public class MainController extends SimpleFormController  {


    @Override
    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, Object command, BindException errors)
            throws Exception {

        System.out.println("**************  onSubmit ************************");

         String msg=null;

             msg="Registration success";

        return  new ModelAndView("result","resMsg",msg);
    }


}

我正在做的是默认页面是这个页面中的index.jsp转发到另一个页面。这里得到错误。请找到以下代码:

MainController.java

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                                       http://www.springframework.org/schema/beans/spring-beans.xsd">

 <bean id="sic"  class="com.ht.controller.MainController"/>


 <bean id="suhm"  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
     <property name="mappings">
        <props>
           <prop key="main.htm">sic</prop>

        </props>
     </property>
   </bean> 

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

</beans>                                                

调度-servlet.xml中

<jsp:forward page="main.htm"/>

的index.jsp

<form:form method="post">
  Student no:<form:input path="sno"/><br>
  Student name :<form:input path="sname"/><br>
  Student address :<form:input path="sadd"/><br>
  <input type="submit" value="register"/>
</form:form>

main.jsp中

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
  self = [super initWithCoder:aDecoder];

  if (self.view == nil) {
    NSBundle *mainBundle = [NSBundle mainBundle];
    [mainBundle loadNibNamed:@"MonthDayPicker" owner:self options:nil];

    [self addSubview:self.view];
    return self;

  }

  return nil;
}

我对此没有任何了解。所以请建议我为这个错误做些什么。

1 个答案:

答案 0 :(得分:0)

您需要在创建bean实例

时注入这些类

<bean id="sic" class="com.ht.controller.MainController"> <property name="commandClass" value="You class Package"/> <property name="commandName" value="name of command"/> </bean>