1
Hello.
I’m having trouble getting the css, js, fonts etc of my project on my pages. I am using Spring, typing the address of the css files in the browser but the system is not able to find the correct path. If anyone can help..
Structure of project folders
application-context.xml
<context:component-scan base-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>
Thank you Daniel Beff, I switched to . jsp my pages and did as you described. It all worked out.
– Ger
You’re welcome! I’m glad I could help!
– Daniel Beff