【发布时间】:2014-10-19 23:52:51
【问题描述】:
嗨,我正在尝试将我的默认主页更改为另一个,但我做不到,所以我尝试将页面从默认主页重定向到我想要的主页,但我收到此错误 未找到带有 URI 的 HTTP 请求的映射:
[/myapp/WEB-INF/views/index.html] DispatcherServlet 中的名称 'appServlet'
这是我的设置,当我使用 spring 工具套件创建项目时,我默认保留所有内容
这是我的 servlet-contex.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value="" />
</beans:bean>
<context:component-scan base-package="com.proj.myapp" />
这是我的 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
这是我的默认主页文件
home.jsp
enter code here
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
<c:redirect url="/indice.html"/>
</h1>
</body>
</html>
这是我要重定向的页面
enter code here
<html>
<body>
<h1>
INDICE
</h1>
</body>
</html>
和我的控制器
@Controller
public class HomeController {
@RequestMapping(value = "/")
public String home() {
return "home.jsp";
}
@RequestMapping(value = "/indice.html")
public String indice() {
return "indice.html";
}
}
我得到这个错误
未找到带有 URI 的 HTTP 请求的映射: DispatcherServlet 中的 [/myapp/WEB-INF/views/indice.html] 名称 'appServlet'
【问题讨论】:
标签: java spring spring-mvc web-applications uri