简体   繁体   中英

Including CSS file to JSP

Cannot find the correct path for css that must be included to .jsp file.

The css files are in css folder and jsp is in folder "views" as shown in this picture . Have tried different paths to include it, but without result.

<link href="<c:url value="..." />" rel="stylesheet">
<link href="..." rel="stylesheet"/>

Could someone give information or correct path from .jsp file ?

Since WEB-INF folder is protected by server, you should move css & js folder to upper level, means css & js folder should exists in WebContent folder directly. The structure should be like this:

-WebContent
 -META-INF
 -WEB-INF
 -css
 -js

The relationship between where files physically exist in project structure and where they are in runtime context is a classic problem (in my experience) with Java.

You could try using:

 System.out.println(System.getProperty("user.dir"));

to find out the directory at runtime and use this to build a correct reference to your stylesheet.

you can use ./css/yourfilename as the path
./ means one up the current directory but the best way to do it is using the absolute path there are many advantage of using the absolute paths for example href="http:www.example.com/css/main.css" .

as meantioned by simon the web-inf could also be the problem

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