简体   繁体   中英

I can't import a CSS File in a JSP

I try to add a CSS file to an JSP which is running on tomcat 8. The CSS just changes the appearance of tables. The CSS file is in the same folder as the JSP. I tried using:

<link href="table.css" rel="stylesheet" type="text/css">

but it didn't show any changes. So I tried:

<style type="text/css">
<%@ include file="./table.css" %>
</style>

But this gives me a weird error, when I try to reach the page in my browser on the first try I get 404 - Resource not found but when I try again it works. What can cause this and is there an easier way to import my CSS file in the JSP? I use a servlet to reach the JSP if that matters.

Edit:// I just checked the WAR File i exported and the WEB-INF Folder only contains my classes the Folders of the HTML and JSP Sites are on the root directory of the WAR file.

I'd put all your .css files in a folder named /css right under the root of your WAR. The path would be css/table.css .

Same for JavaScript: create a folder named /js right under the root of your WAR. The path to JavaScript is js/foo.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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