我正在尝试在 Tomcat 中运行一个应用程序。我创建了一个生成 war 文件的应用程序,我将其放在 Tomcat 上以运行该应用程序,但是当我尝试运行时
它给我错误:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/8.0.28
更详细:
06-Nov-2015 16:35:07.052 WARNING [http-nio-8080-exec-51] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/AppletTest/] in DispatcherServlet with name 'mvc-dispatcher'
在 tomcat 的安装目录中,我的应用程序位于
~/apache-tomcat-8.0.28/webapps/
和 index.html
以及其他文件都在
~/apache-tomcat-8.0.28/webapps/AppletTest/WEB-INF/pages/index.html
.
我犯了什么错误?
我的文件:
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">
<display-name>Test</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup></load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
</web-app>
mvc-dispatcher-servlet.xml
:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.something.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.html</value>
</property>
</bean>
</beans>
最佳答案
您已经创建了一个 Spring 应用程序。 在您的 Web.xml 上,您已将所有请求 (/*) 映射到您的 Spring Servlet。
现在,您必须创建一个 Controller 来监听您的 URL。
例子:
@Controller
public class IndexController {
@RequestMapping(value = "", method=RequestMethod.GET)
public String index(Model m) {
return "index/index";
}
}
现在这个方法将监听 {context}/url 并返回 index.html View 。
关于spring - 在 Tomcat 中调用 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33570545/