简体   繁体   English

春季启动时CSS和Java脚本未呈现404错误

[英]CSS and Java Script not rendering 404 error spring-boot

Here is a snippet of the paths I am using: 这是我正在使用的路径的片段:

<link rel="stylesheet" type="text/templates.css" href="../templates/css/superfish.css" th:href="@{../templates/css/superfish.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/style.css" th:href="@{../templates/css/style.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/nivo-slider.css" th:href="@{../templates/css/nivo-slider.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery.qtip.min.css" th:href="@{../templates/css/jquery.qtip.min.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery-ui.css" th:href="@{../templates/css/jquery-ui.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery.fancybox.css" th:href="@{../templates/css/jquery.fancybox.css}"/>
<link rel="stylesheet" type="text/templates.css" href="../templates/css/jquery.fancybox-buttons.css" th:href="@{../templates/css/jquery.fancybox-buttons.css}"/>

在此处输入图片说明

Controller: 控制器:

 @RequestMapping(value="/", method= RequestMethod.GET)
    public String contactForm(@Valid @ModelAttribute("contact") Contact contact, BindingResult bindingResult,
                              HttpServletRequest request, Model model, Device device) throws IOException {

        System.out.println("Inside controller-----------------");

main method: 主要方法:

@SpringBootApplication
@ComponentScan("com.stidham")
public class StidhamFinancialApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(StidhamFinancialApplication.class);
    }

    public static void main(String[] args) {

        SpringApplication.run(StidhamFinancialApplication.class, args

        );
    }
}

Only the html renders, no js or css. 只有html呈现,没有js或CSS。 I have tried several ways and the path I currently have looks correct and even my IDE auto fills as I type in the path. 我尝试了几种方法,当前输入的路径看起来正确,甚至在键入路径时IDE也会自动填充。

In the war file they are also in the correct place. 在战争档案中,它们也位于正确的位置。

在此处输入图片说明

mvn clean install builds correctly, they're no dependency issues. mvn clean install编译正确,没有依赖性问题。 This seems just like a simple path issue that is not working when deployed. 这似乎就像一个简单的路径问题,在部署时不起作用。

---------------Update 1--------------- ---------------更新1 ---------------

<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" type="text/css" href="/css/superfish.css" />
    <link rel="stylesheet" type="text/css" href="/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/css/nivo-slider.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery.qtip.min.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery-ui.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery.fancybox.css" />
    <link rel="stylesheet" type="text/css" href="/css/jquery.fancybox-buttons.css"/>

在此处输入图片说明 new paths 新路

Still getting 404 for js and css: 仍然为js和CSS获得404:

在此处输入图片说明

The folder "templates" is only reserved for thymeleaf to process html. 文件夹“模板”仅保留给百里香处理html。 JavaScript and CSS should be in the folder "static". JavaScript和CSS应位于文件夹“ static”中。 This folder is mapped directly to the root URL for http. 此文件夹直接映射到http的根URL。

Example: File located in ... /resources/static /css/superfish.css 示例:位于... / resources / static /css/superfish.css中的文件

<link rel="stylesheet" href="/css/superfish.css" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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