Java Spring @RequestParam JSP [英] Java spring @RequestParam JSP

查看:154
本文介绍了Java Spring @RequestParam JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前控制器代码:

    @RequestMapping(value = "/city", method = RequestMethod.POST)
public String getWeather(@RequestParam("city") int city_id,
                             @RequestParam("text") String days, //this gives errrors, when i remove this line, then it is okay
                             Model model) {
    logger.debug("Received request to show cities page");
    //int city = 

    // Attach list of subscriptions to the Model
    model.addAttribute("city",  service.getCity(city_id));

    // This will resolve to /WEB-INF/jsp/subscribers.jsp
    return "city";
}

这是我的JSP文件(视图):

this is my JSP file(view):

    <form method="post" action="/spring/krams/show/city">
Vali linn
<select name="city">
    <c:forEach items="${cities}" var="city">
        <option value="<c:out value="${city.id}" />"><c:out value="${city.city}" /></option>
    </c:forEach>
</select><br>
Vali prognoos N päeva kohta(kirjuta 1 hetkese ilma jaoks)
<input type="text name="text">
<input type="submit" value="Test" name="submit" />
</form>

我想从名为TEXT的文本框中获取一个值,但是当我按下提交"按钮时,我得到了

i want to get a value from the textbox named TEXT, but when i press the submit button then i get

HTTP Status 400 - The request sent by the client was syntactically incorrect ().

推荐答案

我正在添加此答案,以便您可以接受它,正如Bozho建议的那样:)

I am adding this answer so that you can accept it, as it was suggested by Bozho :)

HTML中似乎有一个问题: <input type="text name="text">

There seems to be a problem in the HTML: <input type="text name="text">

将其更改为 <input type="text" name="text">并尝试.

我认为在语法上不正确意味着@RequestParam批注中指定的名称与请求参数名称不匹配...可能是由于上述HTML错误.

I think syntactically incorrect means the names specified in the @RequestParam annotations don't match with the request param names... possibly because of the above error in HTML.

这篇关于Java Spring @RequestParam JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆