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>

 

基礎頁面能夠寫成以下的代碼; javascript

 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>css

</body>
</html>html

經過如下語句引入:java

<jsp:include page="/view/base.jsp" flush="true" />

關鍵時刻仍是要用這樣直觀一點:jquery

<script type="text/javascript">
    var pp = "${pageContext.request.contextPath}";
    alert(pp);
</script>

可是引入的js文件裏面這樣是取不到值的,因此繼承仍是有必要的。jsp

好了,先寫到這裏吧,有啥疑問在溝通啊!ui

相關文章
相關標籤/搜索