[英]Spring DispatcherServlet
I have an application that uses Spring with the following configuration 我有一个使用Spring并具有以下配置的应用程序
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/*" location="/" />
<context:component-scan base-package="controller" />
And this is the whole web.xml file 这是整个web.xml文件
<web-app>
<servlet>
<servlet-name>springrest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
The application runs very well on localhost:8080/web, but I want to change it to localhost:8080/web/rest and for doing that I tried to change the url pattern from 该应用程序可以在localhost:8080 / web上很好地运行,但是我想将其更改为localhost:8080 / web / rest,为此,我尝试将url模式从
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
to 至
<servlet-mapping>
<servlet-name>springrest</servlet-name>
<url-pattern>/rest</url-pattern>
</servlet-mapping>
But unfortunately it doesn't work, what am I doing wrong? 但不幸的是,它不起作用,我在做什么错?
With your change you are filtering the URL intercepted by the DispatcherServlet to be only those starting with /rest
and not all /
as before, so you are just reducing the number of URL handled by Spring, not changing mappings. 进行更改后,您会将DispatcherServlet截获的URL过滤为仅以
/rest
开头的URL,而不是以前的所有/
,因此您只需减少Spring处理的URL数量,而不更改映射。 This is not what you want, I am afraid is not possible to "move down one level" (from /web
to /web/rest
) a java web application with some web.xml configuration, you should rewrite your mappings in Spring configuration (what was /
is now /rest
, what was /foo
is now /rest/foo
). 这不是您想要的,恐怕无法“降级”(从
/web
到/web/rest
)带有某些web.xml配置的Java Web应用程序,您应该在Spring配置中重写映射( /
现在是/rest
是什么, /foo
现在是/rest/foo
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.