【问题标题】:Spring get value of dropbox, POST/GET?Spring获取Dropbox的值,POST / GET?
【发布时间】: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) 进行测试。我该怎么做?

如有问题请咨询!!!

【问题讨论】:

    标签: java spring jsp wsdl


    【解决方案1】:

    getCurrentCity方法注解为@RequestMapping,参数为method=RequestMethod.GET,改为RequestMethod.POST

    还将您的方法签名更改为:

    public String getCurrentCity(@RequestParam("city") int city_id, Model model)
    

    并使用 city_id 调用服务的 getCity 方法

    【讨论】:

      猜你喜欢
      • 2023-01-11
      • 1970-01-01
      • 2010-12-29
      • 2013-07-20
      • 2011-10-05
      • 2018-12-23
      • 2012-12-24
      • 1970-01-01
      • 2013-11-01
      相关资源
      最近更新 更多