English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Recently, I have completed the project tasks assigned by the project manager, started to learn Java web, but encountered many problems in the development process. But what troubles me the most is that the import of external css always fails, and it has been troubled for a long time before finding the cause.
Path problem
The most likely reason for css or js import failure is path error, here I give my website directory structure, everyone can refer to it.
Import css code:
<link rel="stylesheet" type="text/css" href="css/login.css">
Remember to set the relative path in the jsp header:
<% String path = request.getContextPath(); String basePath = request.getScheme()+://"+request.getServerName()+:+request.getServerPort()+path+"/"; %>
Filter set
I am because I set a login filter that caused css and js to fail. The solution is very simple, set the request path intercepted by the filter (the URL style associated with the filter) to the corresponding file, for example, I filter jsp files, so my xml part is configured as follows:
<filter-mapping> <filter-name>login</filter-name> <url-pattern>/.jsp</url-pattern> </filter-mapping>
Thank you for reading, I hope it can help everyone, thank you for your support to our site!