I have a problem with my url mappings in Spring MVC. My goal is to map a url with this form: "applicationName/app/".
Here is my 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.
配置了调度程序后,映射的方式将是
{contextPath}/app/app/1
在web.xml文件中,您使用的是/app/*
,在Controller中您再次给了app/1
..so 2个app
进入了URL映射。因此,请尝试按appName/app/app/1
。否则,从web.xml中删除该app
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.