【问题标题】:how to generate a HTTP rquest in a controller spring mvc如何在控制器spring mvc中生成HTTP请求
【发布时间】:2014-06-15 07:44:51
【问题描述】:

我有一个用 bootstrap 创建的表单,我使用 spring MVC。我在这里不使用弹簧安全性。

<form role="form">
    <fieldset>
        <div class="form-group">
            <input class="form-control" placeholder="Username" name="name" type="text" autofocus>
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="Password" name="password" type="password">
        </div>
        <a href="<c:url value="welcome"/>" class="btn btn-lg btn-success btn-block">Login</a>
    </fieldset>
</form>

我想将用户名和密码发送到欢迎 URL。我该怎么做。

现在,当我使用 @RequestParam("name") 注释时,它给出了一个

Required String parameter 'name' is not present

错误。

【问题讨论】:

  • &lt;a&gt; 不会为您的表单做任何事情。使用&lt;button&gt;&lt;input type="submit"/&gt; 提交表单。

标签: spring spring-mvc httprequest http-request-parameters


【解决方案1】:

将表单的“action”属性设置为您要将表单提交到的网址。

url 可以是绝对的 (http://...) 或相对的 (some/path),具体取决于页面所在的位置。

如果服务器需要 POST 请求,您可能需要将表单上的 'method' 属性设置为 POST 。

你也想要一个提交按钮

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 2019-10-16
    • 2012-05-30
    • 2015-10-05
    • 1970-01-01
    • 2012-11-06
    相关资源
    最近更新 更多