【问题标题】:Spring MVC -- nothing happening on submitSpring MVC - 提交时没有发生任何事情
【发布时间】:2013-04-15 23:36:38
【问题描述】:

我的 Spring 3.2 MVC 应用程序中有以下表单。未调用控制器方法。这是我的表格。

<form:form commandName="bulletin" method="post" value="/processBulletin">
    <table>
        <tr>
            <td>Name:</td>
            <td><form:input path="name" maxlength="30" /></td>
        </tr>
        <tr>
            <td>Subject:</td>
            <td><form:input path="subject" maxlength="50" /></td>
        </tr>
        <tr>
            <td valign="top">Message:</td>
            <td><form:textarea path="note" cols="70" rows="20" /></td>
        </tr>
        <tr>
            <td><input type="button" value="Submit bulletin" name="submit" /></td>
            <td>&nbsp;</td>
        </tr>
    </table>
</form:form>

这是我的控制器方法。

@RequestMapping(value = "/processBulletin", method = RequestMethod.POST)
@ModelAttribute("bulletin") Bulletin bulletin, Model model,
        BindingResult result) {
    final BindException errors = new BindException(bulletin, "bulletin");

    bulletinValidator.validate(bulletin, errors);
    if (errors.hasErrors()) {
        return "redirect:/approvedBulletins";
    } else {
        try {
            bulletin.setSubject(bulletin.getSubject().trim());
            bulletin.setName(bulletin.getName().trim());
            bulletin.setNote(bulletin.getNote().trim());
            long now = System.currentTimeMillis();
            Calendar date = Calendar.getInstance();
            date.setTimeInMillis(now);
            bulletin.setDay((date.get(Calendar.MONTH) + 1) + "/"
                    + date.get(Calendar.DATE) + "/"
                    + date.get(Calendar.YEAR));

            bulletinDAO.writeBulletin(bulletin.getName(),
                    bulletin.getSubject(), bulletin.getDay(),
                    bulletin.getNote());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return "FailurePage";
        }
    }

    return "redirect:/approvedBulletins";
}

【问题讨论】:

    标签: forms spring-mvc controller


    【解决方案1】:

    更改提交按钮。:

    input type = "submit"
    

    【讨论】:

      【解决方案2】:

      你正在使用&lt;input type="button" value="Submit bulletin" name="submit" /&gt; 这个标签不会提交表单 - 默认情况下它不会做任何事情。它的主要用途是与 JavaScript 一起作为 AJAX 应用程序或非 ajax 处理 (UI/UX) 的一部分。

      &lt;input type="submit" value="Submit bulletin" name="submit" /&gt; 标签将在用户点击它们时提交表单,除非您使用 JavaScript 另有指定。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-12
        • 1970-01-01
        • 2021-05-13
        • 2019-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多