【问题标题】:how to load js and css file from web content spring mvc如何从 web 内容 spring mvc 加载 js 和 css 文件
【发布时间】:2017-10-19 08:26:55
【问题描述】:

我无法从 webcontent 文件夹加载 JS 和 CSS 文件。我的登录页面没有格式化,请建议我如何加载这个我没有使用 maven。 请找到图片。

【问题讨论】:

  • 我相信它应该放在资源文件夹中

标签: javascript css spring model-view-controller mapping


【解决方案1】:

1) 创建“资源”文件夹。

2) 在你的 xml 文件中添加这个:

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

3) 在您的页面中“使用”它:

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

如果你使用 Java Config,这样的事情就可以完成:

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

【讨论】:

    猜你喜欢
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-18
    • 2016-04-29
    • 1970-01-01
    • 2013-04-12
    相关资源
    最近更新 更多