zoukankan      html  css  js  c++  java
  • 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文件里面这样是取不到值的,所以继承还是有必要的。

    好了,先写到这里吧,有啥疑问在沟通啊!




  • 相关阅读:
    vim encoding
    window线程间通信常用的三种方法
    Python与C之间的相互调用(Python C API及Python ctypes库)
    vim中去掉每一行的^M
    现实点,不要急! [ 公司软件过程改进案例]
    理解TCP/IP协议
    Linux下C/C++帮助手册安装方法 及使用方法
    MySQL主主高可用(keepalive)
    React获取DOM元素ref属性
    一些vue组件库
  • 原文地址:https://www.cnblogs.com/wshsdlau/p/5661098.html
Copyright © 2011-2022 走看看