工程的jsp引入不了css

J2EE 码拜 9年前 (2015-04-04) 1547次浏览 0个评论

页面:
工程的jsp引入不了css
在index.jsp中引入
<link rel=”stylesheet”  type=”text/css”  href=”style/layout.css”>
用ctrl+左键点击“style/layout.css”可以点进去,但是就是没有效果
把href改成href=”E:/Workspaces/MyEclipse 10/myBlog/WebRoot/style/layout.css”这种也不行

工程的jsp引入不了css
10分
是不是把静态资源,拦截了?
用的什么 mvc ? sping mvc ?
工程的jsp引入不了css
10分
可以在浏览器环境下调试 F12
如果是chrome,在network里面找到那个css,看看是不是路径错误
工程的jsp引入不了css
10分
你可以通过jsp的path 试试全路径引用  href=”<%=path%>/style/layout.css”
另外 检查你是否使用spring mvc框架 把静态资源拦截了
其次 你可以把样式抽出来 放到jsp 内部样式确认是否有效果
工程的jsp引入不了css
引用 1 楼 ZuxiangHuang 的回复:

是不是把静态资源,拦截了?
用的什么 mvc ? sping mvc ?

是的springmvc

工程的jsp引入不了css
10分
那可能是拦截了静态资源,
在spirngmvc-servlet.xml里
加上
<mvc:resources mapping=”/style/**” location=”/style/”/>
试试
工程的jsp引入不了css
引用 5 楼 ZuxiangHuang 的回复:

那可能是拦截了静态资源,
在spirngmvc-servlet.xml里
加上
<mvc:resources mapping=”/style/**” location=”/style/”/>
试试

加了还是不行,然后我去网上搜关于springmvc拦截静态资源的处理方法
加上“<mvc:default-servlet-handler />”也不行

工程的jsp引入不了css
引用 3 楼 huangcan_liu 的回复:

你可以通过jsp的path 试试全路径引用  href=”<%=path%>/style/layout.css”
另外 检查你是否使用spring mvc框架 把静态资源拦截了
其次 你可以把样式抽出来 放到jsp 内部样式确认是否有效果

加到内部是行的,用的是springmvc 加了<mvc:resources mapping=”/style/**” location=”/style/”/>也不行

工程的jsp引入不了css
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.2.xsd
	http://www.springframework.org/schema/mvc
	http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

	<!-- 注解扫描包 -->
	<context:component-scan base-package="com.elf" />

	<!-- 开启注解 -->
	<mvc:default-servlet-handler />
	<mvc:annotation-driven />

	<mvc:resources location="/style/" mapping="/style/**"/>  

	<!-- 定义视图解析器 -->
 	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean> 
</beans>

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明工程的jsp引入不了css
喜欢 (1)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!