【问题标题】:Spring MVC Resources Not WorkingSpring MVC 资源不工作
【发布时间】:2014-06-17 03:58:08
【问题描述】:

我已经查看了其他答案,但仍然遇到问题。 这是我的上下文文件:

<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.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-4.0.xsd">

<context:component-scan base-package="com.tehras.web.controllers"></context:component-scan>
    <context:annotation-config></context:annotation-config>
    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <mvc:annotation-driven/>
    <mvc:resources mapping="/resources/**" location="/resources/"/>
</beans>

这是我的 JSP:

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Paul Laros">
    <link rel="shortcut icon" href="favicon.ico">

    <title>Von - Minimalist Blog Theme</title>

    <!-- Fonts -->
    <link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro%3A400%2C400italic%2C700" rel="stylesheet">
    <link href="http://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet">

    <!-- Bootstrap core CSS -->
    <link href="resources/css/bootstrap.min.css" rel="stylesheet">
    <link href="<c:url value="/resources/css/font-awesome.min.css"/>" rel="stylesheet" type="text/css"/>
    <link href="${pageContext.request.contextPath}/resources/css/bootstrap-social.css" rel="stylesheet">

    <!-- Styles -->
    <link href="${pageContext.request.contextPath}/resources/css/main.css" rel="stylesheet">

    <!-- Loading bar -->
    <script src="${pageContext.request.contextPath}/resources/js/pace.min.js"></script>

    <!-- HTML5 shiv for IE8 support -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <![endif]-->
</head>

请帮忙!

我的文件夹结构是资源文件夹与我的 servlet 文件位于同一目录中。

如果需要,我可以发布更多信息,但我已经阅读了许多建议,但我看不出这有什么问题! 谢谢!

更新:这是我的 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"
    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">
    <display-name>Taras's Blog</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <description></description>
        <display-name>blog</display-name>
        <servlet-name>blog</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>blog</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

【问题讨论】:

  • 请添加您的 web.xml
  • 找不到web.xml有什么问题,能否指定project/war目录结构?
  • 我的资源文件夹在错误的目录中 :(。愚蠢的错误,我的错!

标签: spring model-view-controller resources


【解决方案1】:

我的资源文件夹在此处的错误文件夹中,如果您也遇到问题,请检查,如果正确,那么您可以使用上面的 web.xml 和 context.xml,因为它们是有效的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 2019-12-02
    相关资源
    最近更新 更多