0
Java Web App에서 이미지, 스타일 시트 및 스크립트와 같은 정적 리소스를 제공하려는 일반적인 문제인 것처럼 보이는 것을 해결하려고합니다. 다른 스레드에서 제공되는 많은 솔루션을 시도했지만 아무데도 얻지 못했습니다. 리소스 호출에서 404 오류가 발생합니다.Spring MVC 3.1 정적 리소스 제공
제가 생각할 수있는 유일한 다른 점은 Tomcat 7에서 실행 중이지만 6을 넣으면 "서버가 J2EE 웹 모듈 사양의 버전 3.0을 지원하지 않습니다."라는 메시지가 나타납니다. 오류, 그래서 그것은 가지 않는 것처럼 보입니다. 누구든지 내가 잘못 될 수있는 아이디어가 있습니까?
내 프로젝트도록 구성된다 :
WebContent
META-INF
Resources
CSS
Images
close.jpg
Scripts
WEB-INF
Lib
Views
index.jsp
의 Web.xml
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
스프링 서블릿
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="uk.ac.ncl.controllers" />
<mvc:resources mapping="/resources/**" location="/resources" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
내 컨트롤러
01,235 16,@RequestMapping(value="/", method = RequestMethod.GET)
public String index()
{
return "index";
}
내보기
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Spring 3.0 MVC Series: Index - ViralPatel.net</title>
</head>
<body>
<h1>Page with image</h1>
<!-- use c:url to get the correct absolute path -->
<img src="<c:url value="/resources/images/close.png" />" />
<img src="http://localhost:8080${pageContext.request.contextPath}/resources/images/close.png" />
<a href="map">View Map</a>
</body>
나는 두려워하지 않으며, 모든 것을 소문자로 변경했으며 여전히 작동하지 않습니다. – Mark