简体   繁体   中英

how to load js and css file from web content spring mvc

I am unable to load JS and CSS file from webcontent folder.My login page goes without formatting please suggest me how to load this I am not using maven. Plz find the image. 在此处输入图片说明 在此处输入图片说明

1) Create "resources" folder.

2) Add this in your xml file:

<mvc:resources mapping="/resources/**" location="/resources/" />

3)"Use" it in your page:

<link href="<c:url value="/resources/name_of_file.css" />" rel="stylesheet">

If you use Java Config, something like this will do the job:

@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
          .addResourceHandler("/resources/**")
          .addResourceLocations("/resources/"); 
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM