【发布时间】:2015-12-02 15:01:51
【问题描述】:
我是 Spring 框架的新手。我正在尝试使用 spring 创建一个测试应用程序。视图运行良好,但在我的 JSP 上我无法使用静态内容。 即使我尝试直接访问它们,它们也不会打开。 我已经尝试了我在网上找到的所有解决方案。 如果我遗漏了什么,请告诉我。
这是我的 springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/"/>
<context:component-scan base-package="com.portal"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
以下是我的 web.xml 条目
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
我有一些静态文件位于
/src/static/img/apple-touch-icon.png
/src/static/css/bootstrap.css
/src/static/css/bootstrap.min.css
/src/static/css/styles.css
/src/index.html
但是当我输入网址时
http://localhost:8080/springdemo/index.html
或
http://localhost:8080/springdemo/static/img/apple-touch-icon.png
显示 404。:(
还有
<link rel="apple-touch-icon" href="/springdemo/static/img/apple-touch-icon.png">
或
<link rel="apple-touch-icon" href="http://localhost:8080/springdemo/static/img/apple-touch-icon.png">
不工作。
请帮助我,因为我刚刚开始学习 Spring。
【问题讨论】:
标签: java spring spring-mvc tomcat tomcat7