404 - 请求资源不可用 - Spring MVC 3

时间:2013-11-10 15:35:36

标签: java jsp servlets spring-mvc tomcat7

我正在尝试在我的web应用程序中使用Spring框架,但在尝试设置时我遇到了麻烦。我知道很多人都问了一些与我的问题相似的东西,但是我不能用我见过的所有提示解决我的问题。

请参阅下面的代码,我的代码尝试使用Spring框架打开.html文件。

的web.xml

<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    id="WebApp_ID" version="2.5">

<servlet>
    <servlet-name>fitTrackerServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB INF/config/servlet-config.xml</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>fitTrackerServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
  <display-name>Archetype Created Web Application</display-name>


</web-app>

servlet的config.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"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.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-3.2.xsd">

<mvc:annotation-driven/>
<context:component-scan base-package="com.pluralsight.controller"/>

<!--  
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB INF/jsp/"></property>
    <property name="suffix" value=".jsp"/>
</bean>
-->

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB INF/jsp" p:suffix=".jsp">

</bean>
</beans>

的index.jsp

<html>
<body>
<h2>Hello World!</h2>
<H4>Welcome</H4>
</body>
</html>

的hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>${greeting}</h1>
</body>
</html>

addMinutes.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Minutes Page</title>
</head>
<body>
    <h1>Add Minutes Exercised</h1>
    <form:form command name="exercise">
        <table>
            <tr>
                <td>Minutes Exercise Today</td>
                <td><form:input path="minutes"/></td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Enter Exercise"/>
                </td>
            </tr>
        </table>
    </form:form>
</body>
</html>

结果:

HTTP Status 500 - Servlet.init() for servlet fitTrackerServlet threw exception type Exception report

消息
Servlet.init() for servlet fitTrackerServlet threw exception

描述
The server encountered an internal error that prevented it from fulfilling this request.

例外

javax.servlet.ServletException: Servlet.init() for servlet fitTrackerServlet threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

我正在使用Apache Tomcat 7.0.41
我正在使用localhost:8080/FitnessTracker/addMinutes.html
我无法打开html页面。

我可以在这里找到什么?

1 个答案:

答案 0 :(得分:0)

如果没有看到Java代码,很难判断它是否是一个主要原因,但是你在这里缺少一个破折号:

<property name="prefix" value="/WEB INF/jsp/"></property>

我假设您使用标准命名约定,应该是WEB-INF而不是WEB INF

<property name="prefix" value="/WEB-INF/jsp/"></property>