【发布时间】:2011-04-27 06:20:52
【问题描述】:
这是我对 /weather 的看法:
JSP 文件
....
<form method="post" action="/spring/krams/show/city">
<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>
<input type="submit" value="Test" name="submit" />
</form>
.....
图片!!
这是我的 /weather 控制器:
@RequestMapping(value = "/weather", method = RequestMethod.GET)
public String getCurrentWeather(Model model) {
logger.debug("Received request to show cities page");
// Attach list of subscriptions to the Model
model.addAttribute("cities", service.getAllCities());
// This will resolve to /WEB-INF/jsp/subscribers.jsp
return "weather";
}
这是我对 /city 的看法:
JSP 文件!
....
<h1>Cities</h1>
<c:out value="${city.city}" />
....
这是我的 /city 控制器:
@RequestMapping(value = "/city", method = RequestMethod.GET)
public String getCurrentCity(Model model) {
logger.debug("Received request to show cities page");
model.addAttribute("city", service.getCity(2));
// This will resolve to /WEB-INF/jsp/citys.jsp
return "city";
}
当我按下按钮时,它应该转到我的 /city 页面并显示我从 service.getCity(2) 获得的城市。
我的问题:
当我只是转到 url /city 时,它会从数据库中获取第二个城市..IT WORKS..getCity 方法有效...但是当我按下提交按钮时,它不起作用..它给了我很多错误..但我认为我只是使用错误的语法
我的问题: 基本上我希望它将保管箱值传递给 /city 并且在 /city 控制器中它应该 getCity(x) ,目前我正在使用 getCity(2) 进行测试。我该怎么做?
如有问题请咨询!!!
【问题讨论】: