xml - Cannot load local css in Spring MVC 4 (eclipse) -
i think have config correctly, cannot load css. seems never work. have googled of results, none of them work me. not sure doing wrong.
pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.alias</groupid> <artifactid>yayawine</artifactid> <packaging>war</packaging> <version>0.0.1-snapshot</version> <name>yayawine maven webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>4.0.1.release</spring.version> </properties> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- spring dependencies --> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-web</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> <version>${spring.version}</version> </dependency> <dependency> <groupid>javax.servlet</groupid> <artifactid>jstl</artifactid> <version>1.2</version> </dependency> </dependencies> <build> <finalname>yayawine</finalname> </build> </project>
web.xml
<web-app id="webapp_id" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>archetype created web application</display-name> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/dispatcher-servlet.xml</param-value> </context-param> s <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> </web-app>
dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="wine.controller" /> <bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix"> <value>/web-inf/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> <mvc:annotation-driven /> <mvc:resources mapping="/css/**" location="/resources/css" /> <mvc:default-servlet-handler /> </beans>
index.jsp
<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head lang="lang"> <meta name="viewpoint" content="width=device-width, initial-scale=1"> <link href="/css/bootstrap.css " rel="stylesheet" > <link href="/css/test.css " rel="stylesheet" > <title>hello</title> </head> <body> <h2>hello world!</h2> </body> </html>
update link
tag in jsp
below.
<link href="${pagecontext.request.contextpath}/css/bootstrap.css" rel="stylesheet" > <link href="${pagecontext.request.contextpath}/css/test.css" rel="stylesheet" >
Comments
Post a Comment