1

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

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

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

你能帮我解决什么问题吗..

索引.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()));

}

}

4

1 回答 1

1

你必须使用html给出的标签,或者spring给出的标签。index.jsp 的第一行语法错误。将其设为 ,然后重试。

于 2013-06-21T16:20:09.510 回答