Home> php教程> PHP开发> body text

Solve the problem of introducing external css or js failure into jsp website

高洛峰
Release: 2016-12-08 13:46:21
Original
1490 people have browsed it

I recently worked on a project, completed the tasks assigned by the project manager, and started to get started with java web. However, I encountered many problems during the development process. But the biggest headache for me was that the imported external css kept failing. It took me a long time to find out the reason. .

Path problem

The most likely reason for css or js import failure is the path error. Here I give the directory structure of my website for your reference.

Solve the problem of introducing external css or js failure into jsp website

Import css code:


Remember that the jsp header needs to set a relative path :

<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
Copy after login

Set a filter

It was because I set a login filter that the css and js failed. The solution is very simple. Set the request path intercepted by filter (the URL pattern associated with the filter) to the corresponding file. For example, I am filtering jsp files, so my xml part is configured as follows:

 login /.jsp 
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!