admin管理员组

文章数量:1390890

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(".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. 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.

In the war file they are also in the correct place.

mvn clean install builds correctly, they're no dependency issues. This seems just like a simple path issue that is not working when deployed.

---------------Update 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:

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(".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. 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.

In the war file they are also in the correct place.

mvn clean install builds correctly, they're no dependency issues. This seems just like a simple path issue that is not working when deployed.

---------------Update 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:

Share Improve this question edited Jan 6, 2017 at 23:19 Mike3355 asked Jan 6, 2017 at 12:46 Mike3355Mike3355 12.1k26 gold badges112 silver badges204 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The folder "templates" is only reserved for thymeleaf to process html. JavaScript and CSS should be in the folder "static". This folder is mapped directly to the root URL for http.

Example: File located in ... /resources/static/css/superfish.css

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

本文标签: javascriptCSS and Java Script not rendering 404 error springbootStack Overflow