【问题标题】:404 - Request resource is not available - Spring MVC 3404 - 请求资源不可用 - Spring MVC 3
【发布时间】:2013-11-10 15:35:35
【问题描述】:

我正在尝试在我的 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>

你好.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 页面。

我会在这里遗漏什么?

【问题讨论】:

  • 向我们展示您的fitTrackerServlet

标签: java jsp servlets spring-mvc tomcat7


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 2014-08-25
    • 2014-01-31
    相关资源
    最近更新 更多