[英]Java spring @RequestParam JSP
當前 controller 代碼:
@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 文件(查看):
<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 的文本框中獲取一個值,但是當我按下提交按鈕時,我得到了
HTTP Status 400 - The request sent by the client was syntactically incorrect ().
我正在添加這個答案,以便您可以接受它,正如 Bozho 所建議的那樣:)
HTML 好像有問題: <input type="text name="text">
將其更改為<input type="text" name="text">
並嘗試。
我認為語法不正確意味着@RequestParam
注釋中指定的名稱與請求參數名稱不匹配......可能是因為 HTML 中的上述錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.