Css not found html page - SpringFramework

1

Hello.

I'm having trouble getting the css, js, fonts etc from my project on my pages. I'm using Spring by entering the address of the css files in the browser but the system is not managing to find the path correctly. If anyone can help ..

Project Folder Structure

application-context.xml

<context:component-scanbase-package="com.gervasios.sgr" />

    <mvc:annotation-driven/>

    <mvc:view-controller path="/" view-name="index"/>

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

    <mvc:resources mapping="/resources/**" location="/resources/" cache-period="120"/>

    <mvc:default-servlet-handler />

web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         metadata-complete="true" version="3.0">
    <display-name>sgr-application</display-name>
    <servlet>
        <servlet-name>Spring-Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/application-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring-Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

login.html

<!DOCTYPE html>
<html lang="pt-BR">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Login</title>

    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/resources/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/resources/fonts/font-awesome/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/resources/css/animate.min.css"/>
    <link rel="stylesheet" href="/resources/css/login.css"/>
    <link rel="stylesheet" href="/resources/css/custom.css">
    <link rel="stylesheet" href="/resources/css/icheck/flat/green.css">

    <script src="/resources/js/jquery-1.11.1.min.js"></script>

</head>

<body style="background:#F7F7F7;">
   //codigos.....
   //codigos.....
</body>
</html>
    
asked by anonymous 27.04.2016 / 01:53

1 answer

1

Retrieved from this link:

link

1 - Put your static files in this folder webapp \ resources

2 - Create spring mapping

3 - Include the link in the view via JSTL tag c:url or Spring tag spring:url

Spring Resource Mapping

In your configuration file you will map where your static files will be:

<mvc:resources mapping="/resources/**" location="/resources/seus-estaticos/" />

Including in view

With JSTL tag

<head>
    <link href="<c:url value="/resources/css/main.css" />" rel="stylesheet">
    <script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />"></script>
    <script src="<c:url value="/resources/js/main.js" />"></script>
</head>

With sprint tag

<head>
    <spring:url value="/resources/css/main.css" var="mainCss" />
    <spring:url value="/resources/js/jquery.1.10.2.min.js" var="jqueryJs" />
    <spring:url value="/resources/js/main.js" var="mainJs" />

    <link href="${mainCss}" rel="stylesheet" />
    <script src="${jqueryJs}"></script>
    <script src="${mainJs}"></script>
</head>

I hope I have helped! : D

    
27.04.2016 / 20:27