Eclipse中写jsp文件时,发现里面加载不了js文件和css文件(解决css文件在eclipse中显示不了)
2017年06月15日 08:56:49 欧阳思海 阅读数:9434
版权声明:本文为本人辛苦原创文章,如果需要转载,请注明出处,谢谢!!! https://blog.csdn.net/sihai12345/article/details/73274367
今天在做项目的时候,在项目中新建jsp文件和js文件和css文件,启动服务器,访问页面,加载不到js文件和css文件;(文件存在)
jsp文件部分代码如下:
<link rel="stylesheet" type="text/css" href="static/theme/css/yuqing/easyui.css">
<link rel="stylesheet" type="text/css" href="static/theme/css/yuqing/icon.css">
<link rel="stylesheet" type="text/css" href="static/theme/css/yuqing/demo.css">
<script type="text/JavaScript" src="static/js/ywzbindex/yuqing/jQuery.min.js"></script>
<script type="text/javascript" src="static/js/ywzbindex/yuqing/jquery.easyui.min.js"></script>.
这样就加载不了js文件和css文件;看了一下服务器里面也有相关文件,就是加载不了;
网上查了一下;
方法一:加上:${pageContext.request.contextPath }/
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/theme/css/yuqing/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/theme/css/yuqing/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/theme/css/yuqing/demo.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/ywzbindex/yuqing/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/js/ywzbindex/yuqing/jquery.easyui.min.js"></script>.
方法二:
<%@ page language="Java"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%Stringpath =request.getContextPath();StringbasePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE html>Insert title here/static/theme/css/yuqing/easyui.css"">/static/theme/css/yuqing/icon.css"">/static/theme/css/yuqing/demo.css"">/static/js/ywzbindex/yuqing/jquery.min.js"">/static/js/ywzbindex/yuqing/jquery.easyui.min.js"">
<%@ page language="Java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>/static/theme/css/yuqing/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>/static/theme/css/yuqing/icon.css">
<link rel="stylesheet" type="text/css" href="<%=basePath%>/static/theme/css/yuqing/demo.css">
<script type="text/javascript" src="<%=basePath%>/static/js/ywzbindex/yuqing/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/static/js/ywzbindex/yuqing/jquery.easyui.min.js"></script>
</head>
注意
这个我也不知道为什么,eclipse中的存放css的文件不要用static的文件夹来放置,不然怎么都会显示不出来。
---------------------
作者:欧阳思海
来源:CSDN
原文:https://blog.csdn.net/sihai12345/article/details/73274367
版权声明:本文为博主原创文章,转载请附上博文链接!
网友评论