简体   繁体   中英

how to add external css file in spring web aplication

WebContent> META-Inf>resources>theme1>css> main.css file

Can you please help me to find why i am unable to use the external css file in my web application.

i have created a main.css file in webContent as shown above. i have beed stuck with this issue for a week.

enter code here
**jsp**

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<spring:url value="/resources/theme1/css/main.css" var="main" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link href="${main}" rel="stylesheet" />

spring dispatcher servelet

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
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-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="com.mkyong.common.controller" />
<mvc:annotation-driven />

 <context:component-scan base-package="com.tripapplication.LoginController."></context:component-scan>
 <context:component-scan base-package="com.tripapplication.RegisterController."></context:component-scan> 
<!--  <context:component-scan base-package="com.tripapplication.TripInfoFirstController."></context:component-scan> -->
<!--  <context:component-scan base-package="com.tripapplication.TripInfoSecondController."></context:component-scan> -->


 <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <property name="prefix">
            <value>/WEB-INF/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
 </bean>

<mvc:resources mapping="/resources/**" location="/resources/theme1/css"  
    cache-period="31556926"/>
 <mvc:annotation-driven />


</beans>

This folder structure. Show the settings.

<resources mapping="/resources/**" location="/resources/" />

在此处输入图片说明

( my html in css )

<!-- custom jquery -->
<script th:src="@{/custom/jquery/jquery.js}"></script>

<!-- custom css -->
<link rel="stylesheet" type="text/css" th:href="@{/custom/jquery/jquery_ui/jquery-ui.min.css}" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM