[英]Using @RequestMapping as default welcome file
I saw in this post that I could use the below example to define a default controller/page 我在这篇文章中看到,我可以使用以下示例来定义默认的控制器/页面
@RequestMapping(value={"/content/edit", "/"}, method=RequestMethod.GET)
Unfortunately it's not working. 不幸的是,它不起作用。 When I open my app it shows a 404 error unless I look for
/content/edit.htm
当我打开我的应用程序时,除非我寻找
/content/edit.htm
否则它将显示404错误。
my web.xml 我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
Your servlet is mapped to "*.htm". 您的servlet映射到“ * .htm”。 "/" does not match that pattern, so your servlet and thus your controller has no chance of being invoked.
“ /”与该模式不匹配,因此您的servlet和因此的控制器都没有被调用的机会。 I think you can specify the welcome file (that's what / is) in web.xml, I would have to look up how, though.
我认为您可以在web.xml中指定欢迎文件(即/是),不过,我必须查找如何。
Your problem this in that "/content/edit.htm" is not mapping for 您的问题在于“ /content/edit.htm”未映射为
@RequestMapping(value={"/content/edit", "/"}, method=RequestMethod.GET).
@RequestMapping(value = {“ / content / edit”,“ /”},method = RequestMethod.GET)。
You need 你需要
@RequestMapping(value={"/content/edit.htm", "/"}, method=RequestMethod.GET).
@RequestMapping(value = {“ / content / edit.htm”,“ /”},method = RequestMethod.GET)。
or 要么
@RequestMapping(value={"/content/edit.*", "/"}, method=RequestMethod.GET).
@RequestMapping(value = {“ / content / edit。*”,“ /”},method = RequestMethod.GET)。
You can choose the last option because you filter web.xml to *. 您可以选择最后一个选项,因为您将web.xml过滤为*。 htm
htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.