Java springmvc:URL模式
这是我的web.xmlJava springmvc:URL模式,java,spring,jsp,spring-mvc,servlets,Java,Spring,Jsp,Spring Mvc,Servlets,这是我的web.xml <servlet> <servlet-name>Learn</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup>
<servlet>
<servlet-name>Learn</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Learn</servlet-name>
<url-pattern>/learn/*</url-pattern>
</servlet-mapping>
但我也想点击第一个方法,否则我会添加更多的方法,这是我无法实现的
/learn/abc/
在url映射中
所以请帮我解决这个问题
pom.xml
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- spring-context which provides core functionality -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented
programming implementation allowing you to define -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-webmvc module (also known as the Web-Servlet module) contains
Spring’s model-view-controller (MVC) and REST Web Services implementation
for web applications -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-web module provides basic web-oriented integration features
such as multipart file upload functionality and the initialization of the
IoC container using Servlet listeners and a web-oriented application context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
javax.servlet
servlet api
2.5
朱尼特
朱尼特
3.8.1
测验
org.springframework
spring上下文
4.1.6.1发布
org.springframework
春季aop
4.1.6.1发布
org.springframework
SpringWebMVC
4.1.6.1发布
org.springframework
弹簧网
4.1.6.1发布
如果我错过了此url模式的任何依赖项,请告诉我,要点击您的方法,url路径将是:/learn/learn web.xml上的url模式atribute的工作原理类似于spring的servlet的基本路径。因此,一个好的选择是将url模式更改为/*,如下所示:
<url-pattern>/*</url-pattern>
/*
或者,如果您需要一些基本路径,请将url模式更改为以下内容:
/基本路径/*
要使用您的方法,您需要使用路径url:/basepath/learn,那么如果您不更改
,即将其保留为/learn/*
,会发生什么?对/learn/
和/learn/abc/
的请求都有效吗?它对任何人都有效,但我想要url,因此如果它包含/learn/在其中,那么它会击中控制器,问题是,当您将url更改为/learn/*
时,它没有命中callRequest
方法,对吗?在这种情况下,它没有命中任何方法,但从逻辑上讲它应该。。正当
/learn/abc/
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- spring-context which provides core functionality -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-aop module provides an AOP Alliance-compliant aspect-oriented
programming implementation allowing you to define -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-webmvc module (also known as the Web-Servlet module) contains
Spring’s model-view-controller (MVC) and REST Web Services implementation
for web applications -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<!-- The spring-web module provides basic web-oriented integration features
such as multipart file upload functionality and the initialization of the
IoC container using Servlet listeners and a web-oriented application context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
</dependencies>
<url-pattern>/*</url-pattern>