Java spring @RequestParam JSP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5831239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java spring @RequestParam JSP
提问by Jaanus
current controller code:
当前控制器代码:
@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";
}
this is my JSP file(view):
这是我的 JSP 文件(查看):
<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>
i want to get a value from the textbox named TEXT, but when i press the submit button then i get
我想从名为 TEXT 的文本框中获取一个值,但是当我按下提交按钮时,我得到了
HTTP Status 400 - The request sent by the client was syntactically incorrect ().
回答by naiquevin
I am adding this answer so that you can accept it, as it was suggested by Bozho :)
我正在添加这个答案,以便您可以接受它,正如 Bozho 所建议的 :)
There seems to be a problem in the HTML:
<input type="text name="text">
HTML 中似乎有问题:
<input type="text name="text">
Change it to
<input type="text" name="text">
and try .
将其更改为
<input type="text" name="text">
并尝试。
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.
我认为语法不正确意味着@RequestParam
注释中指定的名称与请求参数名称不匹配......可能是因为 HTML 中的上述错误。