jsp界面的继承与否剖析
引入页面时候
${pageContext.request.contextPath}为页面上下文路径;
也可以用js来实现;
<script type="text/javascript" src="${pageContext.request.contextPath}/js/student_evaluation/studentInfo.js"></script> 相当于: <script type="text/javascript" id="studentInfoJS"></script> <script type="text/javascript"> document.getElementById('studentInfoJS').src = basePath + 'js/student_evaluation/studentInfo.js'; </script>
基础页面可以写成如下的代码;
var basePath = "<%= basePath%>"; 实现全局路径变量,不过${pageContext.request.contextPath}完全可以代替了;
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<script type="text/javascript">
var basePath = "<%= basePath%>";
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>学生成绩信息</title>
<link rel="stylesheet" type="text/css"
href="<%=basePath%>jquery/jquery.bsgrid-1.37/builds/merged/bsgrid.all.min.css">
<script type="text/javascript"
src="<%=basePath%>jquery/jquery-1.12.3.min.js"></script>
<script type="text/javascript"
src="<%=basePath%>jquery/jquery.bsgrid-1.37/builds/js/lang/grid.zh-CN.min.js"></script>
<script type="text/javascript"
src="<%=basePath%>jquery/jquery.bsgrid-1.37/builds/merged/bsgrid.all.min.js"></script>
<script type="text/javascript" src="<%=basePath%>jquery/jquery.bsgrid-1.37/builds/js/util.min.js"></script>
</head>
<body>
</body>
</html>
通过以下语句引入:
<jsp:include page="/view/base.jsp" flush="true" />
关键时刻还是要用这样直观一点:
<script type="text/javascript"> var pp = "${pageContext.request.contextPath}"; alert(pp); </script>
但是引入的js文件里面这样是取不到值的,所以继承还是有必要的。
好了,先写到这里吧,有啥疑问在沟通啊!