jsp介面的繼承與否剖析,jsp介面剖析

來源:互聯網
上載者:User

jsp介面的繼承與否剖析,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檔案裡面這樣是取不到值的,所以繼承還是有必要的。

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

 

 




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.