Directory location and getting project root path

Keywords: JSP Javascript Java JQuery

1, Directory location

1. . / is the current directory. 2. / is the parent directory. 3. / is the root directory. The root directory refers to the top directory. It is relative to the subdirectory.

Under the same level of directory

<link rel="stylesheet" href="css/list_table.css"/>

Get parent directory

afvVoltage.jsp file is imported into the file under incl folder

<%@ include file= "../../../../platform/incl/Include_Header.jsp" %>

2, Get project root path

request.getContextPath() gets the root path of your web project, which is webContent.

The result obtained by ${pageContext.request.contextPath} is the project name (context), as above

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>


<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/platform/views/cusviews/devMatainView/js/layui/css/layui.css"> 
<script src="js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/platform/views/cusviews/devMatainView/My97DatePicker/WdatePicker.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/platform/views/cusviews/devMatainView/js/jquery.form.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/platform/views/cusviews/devMatainView/js/afvVoltage.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/platform/views/cusviews/devMatainView/js/layui/layui.js" charset="utf-8"></script>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<input id="root" type="hidden" value="${ctx }"/>
<input id="ids" type="hidden" value="<%=request.getParameter("ids") %>"/>
<input id="volType" type="hidden" value="<%=request.getParameter("volType") %>"/>
<input id="orandid" type="hidden" value="<%=request.getParameter("orandid") %>"/>

3, Get the full path and port number of the project

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

We can see from the running result that the result is <% = basepath% >

 

Posted by deras on Mon, 23 Dec 2019 09:30:25 -0800