HTML中的外部静态文件无法加载(春季启动)

时间:2020-01-23 14:53:01

标签: html spring

结构为:

target_include_directories(A
    PUBLIC
    $<TARGET_NAME:${CMAKE_CURRENT_SOURCE_DIR}/includes>
)

vue.html是:

src
-main
    --resources
    ---vue.html
    ---example.js

这正在处理警报,我可以看到:我正在活动

404

http://localhost:8080/example.js

它给出了错误。我无法访问该 URL

顺便说一句,最终目的是获得 HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
    <script src="./example.js"></script>

    <script>
        alert("I'm active");


    </script>

我去http://localhost:8080/vue,但我不能去

http://localhost:8080/example.js

它给

@GetMapping("/vue")
public ModelAndView getAllvue() {

    return new ModelAndView("vue");
}

但是,以聪明的主意,当我右键单击html并说在浏览器中打开时,它将转到

http://localhost:63343/myproject/templates/vue.html?_ijt=v7rpc3a98pdc66ml94fp8iikn

,我的脚本有效。这是Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

**example.js**

那么,是什么阻止了我的js工作?

这是安全性配置:

alert("This script will load first");

我也尝试过:

@Configuration
@EnableWebSecurity
//@EnableWebMvc
public class WebSecurity extends WebSecurityConfigurerAdapter {


@Override
protected void configure(HttpSecurity http) throws Exception {

    String[] resources = new String[]{
            "/",
            "/home",
            "/css/**",
            "/icons/**",
            "/images/**",
            "/resources/**",
            "/static/**",
            "/js/**"
    };

  http.csrf().disable();

    http.authorizeRequests()
            .antMatchers(resources).permitAll()
            .and()
            .formLogin()
            .loginPage("/login")
            .loginProcessingUrl("/authenticateTheUser")
            .defaultSuccessUrl("/dashboard")
            .permitAll();
}

也尝试过:

<script src="./example.js"></script>
<script src="../example.js"></script>
<script src="/example.js"></script>
<script src="templates/example.js"></script>

您可以在这里https://stackoverflow.com/a/59855120/11369236

但没有用。

我什至无法访问localhost:8080 / example.js或@Configuration //@EnableWebMvc public class MvcConfig extends WebSecurityConfigurerAdapter implements WebMvcConfigurer {

0 个答案:

没有答案