[英]Spring url mapping does not work
I have a problem with my url mappings in Spring MVC. 我在Spring MVC中的网址映射有问题。 My goal is to map a url with this form: "applicationName/app/".
我的目标是使用以下形式映射网址:“ applicationName / app /”。
Here is my web.xml: 这是我的web.xml:
<?xml version="1.0" ?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
</web-app>
And my Controller: 而我的控制器:
@Controller
public class Controller {
@RequestMapping(value = "app/1")
@ResponseBody
public String test1 (){
return "test1";
}
}
I tried "/app/1" and "/app/1/", but my url mapping does not work. 我尝试使用“ / app / 1”和“ / app / 1 /”,但是我的网址映射不起作用。
配置了调度程序后,映射的方式将是
{contextPath}/app/app/1
在web.xml文件中,您使用的是/app/*
,在Controller中您再次给了app/1
..so 2个app
进入了URL映射。因此,请尝试按appName/app/app/1
。否则,从web.xml中删除该app
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.