【问题标题】:org.springframework.web.servlet.PageNotFound noHandlerFound - error when sending parameterorg.springframework.web.servlet.PageNotFound noHandlerFound - 发送参数时出错
【发布时间】:2014-08-23 11:21:37
【问题描述】:

我们有以下情况

    <a href="<c:url value="/inventory"/>">Example 1</a>
    <a href="<c:url value="/inventory/?type=removed"/>">Example 2</a>

控制器

    @RequestMapping(value = "inventory", method = RequestMethod.GET)
    public String printInventoryPage(
            ModelMap model,
            @RequestParam(value = "type", required = false) String type) {

        return "inventory";
    }

“示例 1”效果很好,但如果我单击“示例 2”会产生类似这样的错误

org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/exampleproject/inventory/resources/js/jquery.js] in DispatcherServlet with name 'spring'

当然,错误适用于所有资源,如 css、javascripts 等。

除了任何网页,我包括所有使用&lt;jsp:include page="header.jsp"/&gt;的资源

可能是什么原因?

【问题讨论】:

    标签: spring jsp servlets


    【解决方案1】:

    您在“/inventory/?type=removed”中的 URI 末尾添加了一个额外的 /。只需写“/inventory?type=removed”。

    您将控制器方法映射到“库存”。恕我直言,将其映射到“/inventory”会更正确。但是“/inventory/”是另一个 URL。

    如果出于任何原因,您需要同时回答这两个问题的方法,请这样声明:

    @RequestMapping(value = {"/inventory", "/inventory/"}, method = RequestMethod.GET)
    public String printInventoryPage( ...
    

    【讨论】:

      【解决方案2】:

      应该是

      @RequestMapping(value = "/inventory", method = RequestMethod.GET)
      public String printInventoryPage(...)
      

      并在?之前从JSP中的url中删除/

      <a href="<c:url value="/inventory?type=removed"/>">Example 2</a>
      

      【讨论】:

        猜你喜欢
        • 2016-02-09
        • 2017-04-17
        • 2016-02-13
        • 2016-08-26
        • 1970-01-01
        • 2020-02-04
        • 2016-09-14
        • 2015-04-03
        • 2016-12-13
        相关资源
        最近更新 更多