Eclipse中写jsp文件时,发现里面加载不了js文件和css文件(解决css文件在eclipse中显示不了)

今天在做项目的时候,在项目中新建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"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title heretitle>
<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的文件夹来放置,不然怎么都会显示不出来。

你可能感兴趣的:(√,css)