3

I disabled the role of the InternalViewResolver in order to access some static pages, html not jsp pages, i made the required changed, indeed i made and i can access my html page, but when i see the browser's console it looks like it didn't bring my local css and js files.

Output 1 of the request

This is my project structure.

Project structure

This is my header page

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>ECommerce view example</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <link rel="stylesheet"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    <script
        src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/static/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="/static/css/login.css"/>
    <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBR8P_sULnn-egsyhOb6qLYG2oqFshTiwY"></script>
</head>

mvc-config.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">

        <annotation-driven></annotation-driven>
        <context:annotation-config></context:annotation-config>
        <context:component-scan base-package="ma.s2m.net"></context:component-scan>         
        <resources mapping="/static/**" location="/WEB-INF/static/"></resources>
    </beans:beans>
M Hamza Javed
  • 1,269
  • 4
  • 17
  • 31
Soufiane Rabii
  • 427
  • 2
  • 8
  • 29

4 Answers4

1

From the browser console, it seems your path is invalid.

<link rel="stylesheet" type="text/css" href="/static/css/style.css"/>

resolved to URL: http://localhost:8080/static/css/style.css.

Context root in URL is missing here. Ideally URL should have been something like this. http://localhost:8080/<CONTEXT_ROOT>/static/css/style.css

In your case, as this is static html page, only one correction is required to match the URI with webapp directory.

Make following changes in entry.html and it would work.

<link rel="stylesheet" type="text/css" href="../static/css/style.css"/> <link rel="stylesheet" type="text/css" href="../static/css/login.css"/>

Hope it solves your error.

Mihir Gohel
  • 316
  • 2
  • 6
1

We generally keep the css,js inside resource folder and the hierarchy is as follows:

webapp
  resource
    static
      css
        style.css
      js
        ...
  WEB-INF
    ...

Try with above hierarchy. Change resource-mapping to

<resources mapping="/resources/**" location="/resources/static/"></resources>.
SachinSarawgi
  • 2,632
  • 20
  • 28
0

You have to use the tag to resolve your static css & js. You can refer How to handle static content in Spring MVC?

Community
  • 1
  • 1
Mrinal N
  • 93
  • 1
  • 5
  • it doesn't change anything. i wanna have an access with no helpers, nothing, no jstl, nothing. exactly like what we do in a spring boot application. – Soufiane Rabii Feb 07 '17 at 13:19
  • your stylesheet links will resolve to webapp/static/css/ directory. As the files are not present in that directory you are getting a 404 error. If you are using a resources tag then you will need to take help of JSTL or spring tag. Another option is to ignore the resource tag and give paths as we give in a static html page. For that all your files should be below the webapp directory as files under WEB-INF folder are secure and can't be directly accessed by a browser client. – Mrinal N Feb 07 '17 at 13:46
  • it didn't work, i adopted the second option, i replaced my resources under webapp folder, this is the link **** – Soufiane Rabii Feb 07 '17 at 13:57
  • Try moving the entire contents of static folder along with the entry.html file under webapp directory & use **** – Mrinal N Feb 07 '17 at 14:19
  • Still nothing, i did what you told me – Soufiane Rabii Feb 07 '17 at 14:42
0

just noticed remove the / from href attribute the will solve this issue.

please try change

<link rel="stylesheet" type="text/css" href="/static/css/login.css"/>

to

<link rel="stylesheet" type="text/css" href="static/css/login.css"/>

hope can help you.

Fong
  • 1