【问题标题】:POST method does not redirects to the controller actionPOST 方法不会重定向到控制器操作
【发布时间】:2016-11-26 03:35:11
【问题描述】:

我在 JSP 中有一个简单的 html 表单,我正在使用 spring mvc。 我正在尝试使用 POST 方法创建一个新用户。 JSP代码是:

<form:form method="post" modelAttribute="user">
    <table>
        <tr>
            <td>SJSU ID</td>
            <td><input type="text" placeholder="6 digit SJSU ID" id="sjsuid" name="sjsuid"></td>
        </tr>
        <tr>
            <td>EmailID</td>
            <td><input type="text" placeholder="Email ID" id="username" name="username"></td>
        </tr>
        <tr>
            <td colspan="3"><input type="submit" value="Create"/></td>
        </tr>
    </table>
    <br>
</form:form>

现在,正如表单标签中指定的那样,我正在尝试在我的控制器操作中访问表单值:

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping(method = RequestMethod.POST)
    public String submitForm(@ModelAttribute("user") User userVO) {
        System.out.println("Submitted");
        userDAO.createUser(userVO.getSjsuid(),userVO.getUsername());
        return "adduser";
    }
}

问题是,我没有收到系统输出消息“已提交”。简而言之,从不调用 submitForm 操作。 谁能告诉我出了什么问题? 我不认为有一些弹簧配置问题,因为相同的设置适用于另一个以前的项目。

谢谢。

【问题讨论】:

  • 您缺少将表单提交与控制器链接的表单的操作属性。

标签: jsp spring-mvc post controller


【解决方案1】:

通过添加解决问题:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

愚蠢的错误困扰着我-_-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-20
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多