Why can't I load js and css files on my pages?

gtludwig

I'm running a SpringMVC + Thymeleaf application and would like to load javascript and CSS on my HTML5 pages.

My login.html is:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"></meta>
<title>Login Page</title>

<meta name="description" content="login page"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1.0"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<link rel="shortcut icon" href="../assets/img/favicon.png"
type="image/x-icon"></link>

<link href="../assets/css/bootstrap.min.css" rel="stylesheet"></link>
<link id="bootstrap-rtl-link" href="" rel="stylesheet"></link>
<link href="../assets/css/font-awesome.min.css" rel="stylesheet"></link>

<link href="http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,400,600,700,300"
rel="stylesheet" type="text/css"></link>

<link id="beyond-link" href="../assets/css/beyond.min.css" rel="stylesheet" ></link>
<link href="../assets/css/demo.min.css" rel="stylesheet"></link>
<link href="../assets/css/animate.min.css" rel="stylesheet"></link>
<link id="skin-link" href="" rel="stylesheet" type="text/css"></link>

<script src="../assets/js/skins.min.js"></script>

<script src="../assets/js/jquery-2.0.3.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<script src="../assets/js/slimscroll/jquery.slimscroll.min.js"></script>

<script src="../assets/js/beyond.js"></script>
</head>

<body>
    <div class="login-container animated fadeInDown">
        <div class="loginbox bg-white">
            <div class="loginbox-title">SIGN IN</div>

            <div class="loginbox-textbox">
                <input type="text" class="form-control" placeholder="Email"></input>
            </div>
            <div class="loginbox-textbox">
                <input type="text" class="form-control" placeholder="Password"></input>
            </div>
            <div class="loginbox-forgot">
                <a href="">Forgot Password?</a>
            </div>
            <div class="loginbox-submit">
                <input type="button" class="btn btn-primary btn-block" value="Login"></input>
            </div>
            <div class="loginbox-signup">
                <a href="register.html">Sign Up With Email</a>
            </div>
        </div>
        <div class="logobox"></div>
    </div>
</body>
</html>

The structure of the webapp folder is: enter image description here

But, though no mapping errors show on the console, I still can't get the nice effects and styles I'm hoping for.

I have a piece of code on my application configuration class that reads:

@Bean
public ViewResolver viewResolver() {
    ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
    templateResolver.setTemplateMode("HTML5");
    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setPrefix("/WEB-INF/html/");
    templateResolver.setSuffix(".html");

    SpringTemplateEngine engine = new SpringTemplateEngine();
    engine.setTemplateResolver(templateResolver);

    ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
    viewResolver.setTemplateEngine(engine);

    return viewResolver;
}

/*
 *  Configure ResourceHandlers to serve static resources like CSS/ Javascript etc...
 */
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/static/**").addResourceLocations("/static/");
registry.addResourceHandler("/WEB-INF/assets/**").addResourceLocations("/WEB-INF/assets/");
}

The commented out registry line for the /static/ folder works nicely on JSP. I've tried, for HTML, both /assets/ and /WEB-INF/assets/. How come it's not working?

user3145373 ツ

I have developed same application like you. Just developed it and working fine for me.

Here is config:

@EnableWebMvc
@Configuration
@ComponentScan(basePackages = { "org.tnt.base.api" })
public class MvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Bean
    public InternalResourceViewResolver jspViewResolver() {
        InternalResourceViewResolver bean = new InternalResourceViewResolver();
        bean.setPrefix("/WEB-INF/views/");
        bean.setSuffix(".html");
        return bean;
    }

    ....

}

Here's a screenshot of my structure that works:

enter image description here

Here's my login.html code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TnT Quick Login</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css" />
</head>
<body>
....

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why can't I load js and css files on my pages?

From Dev

Why can't I delete my files?

From Dev

foundation for apps can't load js and css files

From Dev

can't seem to load CSS and JS to JSF files

From Dev

foundation for apps can't load js and css files

From Dev

Why can't I load files from a folder named 'users'?

From Dev

Why can't I load my page in phantomJS?

From Dev

How I can load a css file in all dashboard pages and my wp theme?

From Dev

Express.js can't get my CSS files

From Dev

Why I can't see my files inside a docker container?

From Dev

Why can't I hide my 'ul' with CSS like this?

From Dev

Can't figure out why CSS is causings only one of my pages to appear incorrectly in mobile?

From Dev

Why can't I use globals in separate html and js files?

From Dev

How can I, and should I, load my .js files from a different file for cleanliness?

From Dev

I can't load my file?

From Dev

I can't seem to get my static files to load using Django

From Dev

Why can't I import header files to a library in one of my header files?

From Dev

Why can't bash see my files?

From Dev

Why can't my script find the files?

From Dev

Why can't my script find the files?

From Dev

My files! Can I save forms, locally against secured pages?

From Dev

Can't load existing js file on gh-pages

From Dev

Why won't my CSS work on GitHub Pages?

From Dev

Why Can't I load google map?

From Dev

socket.IO- why can't my client html page load socket.io.js?

From Dev

Why can't I load modules while executing my bash script, but only when sourcing it?

From Dev

Why IE 10 & 11 can't load GZiped content (js and css)?

From Dev

Why can't I apply my JS event to my EJS code?

From Dev

How can I compress / gzip my mimified .js and .css files before publishing to AWS S3?

Related Related

  1. 1

    Why can't I load js and css files on my pages?

  2. 2

    Why can't I delete my files?

  3. 3

    foundation for apps can't load js and css files

  4. 4

    can't seem to load CSS and JS to JSF files

  5. 5

    foundation for apps can't load js and css files

  6. 6

    Why can't I load files from a folder named 'users'?

  7. 7

    Why can't I load my page in phantomJS?

  8. 8

    How I can load a css file in all dashboard pages and my wp theme?

  9. 9

    Express.js can't get my CSS files

  10. 10

    Why I can't see my files inside a docker container?

  11. 11

    Why can't I hide my 'ul' with CSS like this?

  12. 12

    Can't figure out why CSS is causings only one of my pages to appear incorrectly in mobile?

  13. 13

    Why can't I use globals in separate html and js files?

  14. 14

    How can I, and should I, load my .js files from a different file for cleanliness?

  15. 15

    I can't load my file?

  16. 16

    I can't seem to get my static files to load using Django

  17. 17

    Why can't I import header files to a library in one of my header files?

  18. 18

    Why can't bash see my files?

  19. 19

    Why can't my script find the files?

  20. 20

    Why can't my script find the files?

  21. 21

    My files! Can I save forms, locally against secured pages?

  22. 22

    Can't load existing js file on gh-pages

  23. 23

    Why won't my CSS work on GitHub Pages?

  24. 24

    Why Can't I load google map?

  25. 25

    socket.IO- why can't my client html page load socket.io.js?

  26. 26

    Why can't I load modules while executing my bash script, but only when sourcing it?

  27. 27

    Why IE 10 & 11 can't load GZiped content (js and css)?

  28. 28

    Why can't I apply my JS event to my EJS code?

  29. 29

    How can I compress / gzip my mimified .js and .css files before publishing to AWS S3?

HotTag

Archive