title: My JSP page won't load CSS file
body: <p>I Have Spring MVC application, I'm using Java config, no XML. My JSP cant access CSS file. I googled whole day, tried almost everything. When I inspect my page, in console there is error - <strong>Failed to load resource: the server responded with a status of 404 (Not Found)</strong> I'm using Wildfly server.</p>
  
  <p><img src="https://i.stack.imgur.com/XDL6b.jpg" alt="folder structure"></p>
  
  <p><strong>SpringConfig:</strong></p>
  
  <pre><code>package com.library.config;
  
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.ViewResolver;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
  
  
  @EnableWebMvc
  @Configuration
  @ComponentScan(basePackages = "com.library")
  public class SpringConfig extends WebMvcConfigurerAdapter {
  
      @Bean
      public ViewResolver viewResolver(){
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setPrefix("/resources/views/");
          resolver.setSuffix(".jsp");
          return resolver;
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry.addResourceHandler("/resources/**").addResourceLocations("/resources/static/css/");
      }
  }
  </code></pre>
  
  <p><strong>DispatcherInitializer:</strong></p>
  
  <pre><code>package com.library.config;
  
  import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  
  public class DispatcherInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[] {SpringConfig.class};
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return null;
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] {"/"};
      }
  }
  </code></pre>
  
  <p><strong>JSP page:</strong></p>
  
  <pre><code>&lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
  &lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
  
  &lt;c:set var="context" value="${pageContext.request.contextPath}"/&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;head&gt;
      &lt;title&gt;Login Page&lt;/title&gt;
  
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css"&gt;
      &lt;link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"&gt;
      &lt;link href="&lt;c:url value="${pageContext.request.contextPath}/resources/static/css/style.css" /&gt;" rel="stylesheet"&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h2&gt;${pageContext.request.contextPath}&lt;/h2&gt;
  
  &lt;br&gt;
  &lt;div class="row"&gt;
      &lt;div class="container"&gt;
          &lt;div class="login-register-form-section"&gt;
              &lt;ul class="nav nav-tabs" role="tablist"&gt;
                  &lt;li class="active"&gt;&lt;a href="#login" data-toggle="tab"&gt;Login&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#register" data-toggle="tab"&gt;Register&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
              &lt;div class="tab-content"&gt;
                  &lt;div role="tabpanel" class="tab-pane fade in active" id="login"&gt;
                      &lt;form class="form-horizontal" method="post" action=""&gt;
                          &lt;div class="form-group " &gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-user"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;input type="text" name="login_email" class="form-control" placeholder="Username or email" required="required" value=""&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group "&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-key"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;input type="password" name="login_password" class="form-control" placeholder="Password" required="required"&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input type="checkbox" id="rememberMe"&gt;
                              &lt;label for="rememberMe"&gt;Remember Me&lt;/label&gt;
                              &lt;a href="#" class="pull-right"&gt;Forgot password?&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;input type="submit" value="Login" class="btn btn-success btn-custom"&gt;
  
                      &lt;/form&gt;
                  &lt;/div&gt;
                  &lt;div role="tabpanel" class="tab-pane fade" id="register"&gt;
                      &lt;form class="form-horizontal" id="form"&gt;
                          &lt;div class="form-group"&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-user"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;select type="text" id="sex" name="gender" class="form-control"&gt;
                                      &lt;option&gt;Male&lt;/option&gt;
                                      &lt;option&gt;Female&lt;/option&gt;
                                  &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group "&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-male"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;input type="text" id="register_username" class="form-control" placeholder="Username" required="required" value=""&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group "&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-envelope"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;input type="email" id="register_email" class="form-control" placeholder="Email" required="required" value=""&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group "&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-skype"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;input type="text" id="register_skype" class="form-control" placeholder="Skype name" required="required" value=""&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group "&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;div class="input-group-addon"&gt;&lt;i class="fa fa-lock"&gt;&lt;/i&gt;&lt;/div&gt;
                                  &lt;input type="password" id="register_password" class="form-control" placeholder="Password" required="required"&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;input type="submit" id="submitbtn" value="Register" class="btn btn-success btn-custom"&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"&gt;
      &lt;div class="modal-dialog" role="document"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;center&gt;&lt;h5 class="modal-title" id="exampleModalLabel"&gt;Your registration was successful! Please login!&lt;/h5&gt;&lt;/center&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;button type="button" id="confirm" class="btn btn-primary"&gt;Close&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>