I have a web project structure:
src/main/webapp
|__project1
|____css
|__WEB-INF
|____project1
|_____jsp
Part of my web.xml:
<servlet-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-lass>org.springframework.web.servlet.DispatcherServlet</servlet-class>
...
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/project1/*</url-pattern>
</servlet-mapping>
In my jsp page I use:
<link rel="stylesheet" href=${pageContext.request.contextPath}/project1/css/common.css type="text/css"/>
But it's not work. Stylesheet is not available on page.
If I use localhost:9080/project1/css/common.ccs I recieve 404 error.
If I transfer ccs file in folder: src/main/webapp/css, then css is avaliable (localhost:9080/css/common.css).
I think problem in /project1/* intercept servlet and I can't access from css. How fix this problem and save the old architecture?
Remove /project1
while trying to access the resources. Since you have already mapped it inside web.xml
, it will be available in the contextPath
.
<link rel="stylesheet" href=${pageContext.request.contextPath}/css/common.css type="text/css"/>
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.