【问题标题】:RequestMapping redirecting Error404RequestMapping 重定向错误 404
【发布时间】:2013-06-18 19:07:01
【问题描述】:

请帮助我处理 Spring 的 RequestMapping。当我点击国家(url)时,我希望我的网络应用程序打印城市。所以我创建了 WebController,它有这个 RequestMapping。

 @RequestMapping(value = "/cities/{cityId}", method = RequestMethod.GET )
        public List <City> searchCityById( @PathVariable ("cityId") Long cityId) {


            return ciserv.searchCityById(cityId);
        }

ciserv - 我的服务,它工作正常 和 countrylist.jsp,其中有

<c:forEach items="${countryList}" var="country">

        <br />
        <td><a href="cities/${country.id}">${country.name}</a></td>
    </c:forEach>

所以当我单击国家/地区 url 时,它会打印我的国家/地区(带有 url),它会将我正确地重定向到 localhost/myproject/cities/(国家/地区的 ID),但它显示错误 404 - 资源不可用。我该如何解决?我的 webapp 的这个功能需要与 RequestMapping 一起使用还是需要以其他方式使用?感谢您的帮助!

【问题讨论】:

  • 看起来您正在使用国家/地区链接/URL 的相对路径。生成这些链接的 JSP 视图的 URL 是什么?您是否尝试过使用/cities/${country.id} 代替链接?您的应用程序的上下文根是什么?什么是 servlet 映射?

标签: spring jsp


【解决方案1】:

有几件事看起来很奇怪:

  • 你在网址中混合了城市和国家
  • 使用'c:url'!

例子:

   <c:url var="countryUrl" value="/country/${country.id}”/>
  <a href="${countryUrl}"> . . .

【讨论】:

    猜你喜欢
    • 2017-09-18
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 2017-05-10
    • 2013-05-05
    相关资源
    最近更新 更多