【发布时间】:2017-07-05 18:19:09
【问题描述】:
我有 HomeController 类:
@Controller
public class HomeController {
@RequestMapping("/")
public String showPage() {
return "main-menu";
}
}
春季版:4.3.9 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<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>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>*.form</url-pattern>
</servlet-mapping>
</web-app>
调度程序-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
</beans>
它总是显示 index.jsp,从不显示 main-menu.jsp 我想要一个主菜单我的主页。我该怎么办?
【问题讨论】:
-
spring 默认将 index.jsp、index.html 等作为欢迎页面。可以根据这篇文章stackoverflow.com/a/29054676/3981536 禁用此功能
-
所以我不能用其他名字设置主页?
-
可以,但是需要覆盖spring的默认行为
-
同样在spring启动日志中验证,如果请求端点注册了..
-
告诉我们
dispatcher-servlet.xml和web.xml
标签: java spring jsp spring-mvc