1

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";
}
4

2 に答える 2

1

ボタンを送信するように変更します。

input type = "submit"
于 2013-04-16T08:14:18.697 に答える
0

このタグを使用している場合<input type="button" value="Submit bulletin" name="submit" />、フォームは送信されません。デフォルトでは何もしません。主な用途は、AJAX アプリケーションまたは非 ajax 処理 (UI/UX) の一部として JavaScript と組み合わせて使用​​することです。

<input type="submit" value="Submit bulletin" name="submit" />タグは、JavaScript で特に指定しない限り、ユーザーがクリックしたときにフォームを送信します。

于 2013-04-16T14:04:44.450 に答える