post命令没有使用spring调用控制器

时间:2013-06-11 12:31:44

标签: spring spring-mvc

我正在使用Spring MVC框架将数据从jsp提交到使用dispatcher-servlet.xml中的映射定义的控制器。

但控制器仅在加载期间被调用,我的意思是当我在加载页面时...

当我点击jsp页面中的提交时,控制器中的onsubmit永远不会被命中...

你可以帮我解决一下这个问题..

的index.jsp

<form form method="post"  commandName="postsubmit">
        <table>
            <tr>
                <td> <b>cal pool: </b></td>  <td> <input type="text"> </input> </td>
            </tr>
           <tr>
                <td> <b>date: </b></td>  <td> <input type="text"> </input> </td>
            </tr>
            </br>
            </br>
            <tr>
                <td> <input type="submit" value="submit"/> </td>

            </tr>

        </table>
        </form>

调度-servlet.xml中

<bean name="/index.htm" class="PostSubmitController">
    <property name="sessionForm" value="true"/>
    <property name="commandName" value="postsubmit"/>
    <property name="commandClass" value="PostSubmit"/>
    <property name="formView" value="index"/>
    <property name="successView" value="success.htm"/> 
    <property name="postSubmit" ref="postSubmit"/>

</bean>     

PostSubmitController

public class PostSubmitController extends SimpleFormController{
   private PostSubmit _postsubmit; 

   protected final Log logger = LogFactory.getLog(getClass()); 

     public ModelAndView onSubmit(Object command)
            throws ServletException { 
         System.out.println("hello");
         logger.info("debug1");
        String _getcal_pool = ((PostSubmit) command).getCal_pool();
        logger.info("debug2");
        Date _getcal_date = ((PostSubmit) command).getDate();
        logger.info("debug3");
        logger.info("get_cal_pool:" +   _getcal_pool );
        logger.info("get_cal_date:" +   _getcal_date.toString() );
        logger.info("debug4");
        logger.info("returning from PostSubmitController view to " + getSuccessView()); 
        return new ModelAndView(new RedirectView(getSuccessView()));
   } 

    public void setPostSubmit(PostSubmit postSubmit) {
        System.out.println("hello");
         logger.info("debug5");
        this._postsubmit = postSubmit;
    } 
    public PostSubmit getPostSubmit() {
         System.out.println("hello");
         logger.info("debug6");
        return _postsubmit;
    } 

public ModelAndView processFormSubmission(HttpServletRequest request,
                                         HttpServletResponse response,
                                         Object command,
                                         BindException errors)
                                  throws Exception
{
    System.out.println("hello in processFormSubmission");
    logger.info("returning from processFormSubmission view to " + getSuccessView()); 
    return new ModelAndView(new RedirectView(getSuccessView()));

}

}

1 个答案:

答案 0 :(得分:1)

你必须使用html提供的标签,或春天给出的标签。 index.jsp的第一行在语法上是错误的。制作它,然后再试一次。