1
jsp 페이지에 CSS 파일을 포함시키고 싶습니다. 나는 stackoverflow, 구글에서 모든 솔루션을 시도 ...하지만 여전히 아무것도, 그것은 CSS 코드를 인식하지 못합니다.스프링 mvc 리소스 파일은 jsp 페이지에 포함될 수 없습니다 (Tomcat v9.0, Spring Tool Suite, Maven)
I이 3 개 솔루션 시도 :
<link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
<spring:url value="/resources/css/main.css" var="mainCss" />
<link type="text/css" href="${pageContext.request.contextPath}/css/main.css" rel="stylesheet" />
서블릿의 context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.projekt.springmvc" />
<annotation-driven />
<resources mapping="/resources/**" location="/resources/css/" />
<default-servlet-handler />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
</beans:beans>
web.xml의
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
home.jsp
봄 도구 스위트로 만든main.css가
body{
padding-top:70px;
font-size:30px;
}
MVC 프로젝트. 이 구성
<link href="<c:url value="/resources/main.css"/>" rel="stylesheet">
설명
:
<resources mapping="/resources/**" location="/resources/css/" />
을 당신은 /resources/css
의 모든 내용을 할당 할 수 있습니다 프로젝트는이 시도 메이븐, JRE_8, 톰캣 V9.0
이클립스 작품,하지만 흥미로운 ... 주셔서 감사합니다 해결책!!! :) – Ivan