在web.xml中,servlet-mapping的url-pattern可以包含多个路径组件吗? (例如/路径/到/*))

问题描述 投票:0回答:1

我发现以下奇怪的行为:

  1. GET http://myserver/myapp/功能性/2.0 有效(调用我的
    @Controller
    方法)
2024-03-14 13:59:49,761 [ajp-nio-172.7.102.11-5067-exec-2] INFO  com.mycompany.MyControllerV2 - MyControllerV2 getSomething4() Begin
  1. GET http://myserver/myapp/功能/2.0/ 不起作用
2024-03-14 13:59:48,048 [ajp-nio-172.7.102.11-5067-exec-1] WARN  org.springframework.web.servlet.PageNotFound - No mapping for GET /myapp/functionality/2.0/
  1. GET http://myserver/myapp/功能/2.0/pathvalue 不起作用

catalina.out

 2024-03-14 13:57:32,953 [main] DEBUG _org.springframework.web.servlet.HandlerMapping.Mappings -
    e.s.a.a.r.c.MyControllerV2:
    {GET [/functionality/2.0/{entity}]}: getSomething2(HttpServletRequest,HttpServletResponse)
    {GET [/functionality/2.0]}: getSomething4(HttpServletRequest,HttpServletResponse)
    {GET [/functionality/2.0/]}: getSomething5(HttpServletRequest,HttpServletResponse)
    {GET [/functionality/2.0/pathvalue]}: getSomething6(HttpServletRequest,HttpServletResponse)
    {GET [/myapp/functionality/2.0/pathvalue]}: getSomething7(HttpServletRequest,HttpServletResponse)
    

web.xml

注意,我有一个版本 1.0,它扩展了普通的旧

HttpServlet
,因此需要这个
/2.0/
路径组件。

        <servlet>
                <servlet-name>NEWAPI</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                <init-param>
                        <param-name>dispatchOptionsRequest</param-name>
                        <param-value>true</param-value>
                </init-param>
                <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
                <servlet-name>NEWAPI</servlet-name>
                <url-pattern>/functionality/2.0/*</url-pattern>
        </servlet-mapping>

NEWAPI-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
                        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

        <!--
                - The controllers are autodetected POJOs labeled with the @Controller annotation.
        -->
        <context:component-scan base-package="edu.mycompany" />
</beans>

技术堆栈

(强制,不是我的选择)

  • 春季5号,
  • Tomcat 9 和
  • Servlet 2.3,

注释

  • 如果这个例子是人为的,我深表歉意,我需要删除公司机密。
  • 我确实阅读了 Servlet 规范,但它似乎没有解决这种情况
spring-mvc servlets web.xml url-mapping
1个回答
0
投票

@RequestMapping
@Controller 中的 url 必须(通常)应该相对于根 url 模式。

如果 Spring 请求映射中的 url 与 web.xml 模式相同,它将作为绝对 url 成功匹配。否则,url 的两个组成部分不应重叠。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.