2

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}"/>

enter image description here

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

enter image description here

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"/>

enter image description here new paths

Still getting 404 for js and css:

enter image description here

1 Answer 1

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" />
Sign up to request clarification or add additional context in comments.

1 Comment

you have forgotten to create an directory named "static"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.