Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}


@Bean
public ViewResolver viewResolver() {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".jsp");
    return resolver;
}

forward is MvcConfig.java. As you can see, i add resourcehandler for static resources.

private void addDispatcherServlet(ServletContext servletContext)
{
    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.getEnvironment().addActiveProfile("production");
    applicationContext.register(MvcConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(applicationContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
    dispatcher.setInitParameter("dispatchOptionsRequest", "true");
} 
private void addUtf8CharacterEncodingFilter(ServletContext servletContext)
{
    FilterRegistration.Dynamic filter = servletContext.addFilter("CHARACTER_ENCODING_FILTER", CharacterEncodingFilter.class);
    filter.setInitParameter("encoding", "UTF-8");
    filter.setInitParameter("forceEncoding", "true");
    filter.addMappingForUrlPatterns(null, false, "/*");
}

And there is Initializer.java

There is my resource hierachy.

src
  -main
    --java
    --resources
    --webapp
      ---WEB-INF
         ----resources
             -----css
                  ------ signin.css
         ----views

In index.jsp,I called signin.css like this.

<link href="/resources/css/signin.css"  rel="stylesheet">

Then, i can found these error message.

WARN [2017-03-07 14:37:49] ({http-bio-8080-exec-14} DefaultHandlerExceptionResolver.java[handleHttpRequestMethodNotSupported]:215) - Request method 'GET' not supported
WARN [2017-03-07 14:37:49] ({http-bio-8080-exec-15} DefaultHandlerExceptionResolver.java[handleHttpRequestMethodNotSupported]:215) - Request method 'GET' not supported

In chrome browser, also has 405 error. [405-Error screen shot][1][1]: https://i.stack.imgur.com/vmDlk.png

How can i fix it?

share|improve this question
    
FYI, if you're using Boot, you can put those resources under src/main/resources/public (or static) and you don't have to configure any of the resolvers yourself. – chrylis 22 hours ago
    
I'm not using Boot,,, i create MVC project for Spring legacy. Then i changed servlet's config to Java code. – Jong Han Kim 22 hours ago

can you change

<link href="/resources/css/signin.css"  rel="stylesheet">

to

<link href="${pageContext.request.contextPath}/resources/css/signin.css"  rel="stylesheet">
share|improve this answer
    
Thanks,,, i tried, but it's not working well... – Jong Han Kim 22 hours ago
    
Have you added this in servlet-context.xml : <resources mapping="/resources/**" location="/resources/" /> – Nimesh 19 hours ago
    
Yeah.... i did... As you can see, addResourceHandlers is method which is the same function in servlet-context.xml <resources> tag. – Jong Han Kim 4 hours ago

try this

registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.