Java spring @RequestParam JSP
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 "ci开发者_运维知识库ty";
}
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>
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 ().
I am adding this answer so that you can accept it, as it was suggested by Bozho :)
There seems to be a problem in the HTML:
<input type="text name="text">
Change it to
<input type="text" name="text">
and try .
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.
精彩评论