jsp page absolute path reference $ {pageContext.request.contextPath} (reprint)

  • $ {PageContext.request.contextPath} JSP method to obtain an absolute path, equivalent to <% = request.getContextPath ()%>.
  • That is, the application name or remove the deployment of the current name of the project
  • For example, my project name is entered as demo1 browser HTTP: // localhost: 8080 / demo1 / pageContext.request.contextPath a.jsp $ { } or <% = request.getContextPath ()%> taken out is / demo1
  • The meaning of "/" represents is http: // localhost: 8080
  • Sometimes it is a project written $ {pageContext.request.contextPath} /a.jsp
  • Compare absolute path relative path
  • May be used when using $ {pageContext.request.contextPath}, also be used <% = request.getContextPath ()%> achieve the same effect,
  • Also be $ {pageContext.request.contextPath}, into a JSP file, with C: set into a variable, and then taken out at the time of use with EL expression. 

The common path on the same label and a page common jsp pages, and the corresponding references jsp


<% @ taglib prefix = "c
<% @ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>
<% @ taglib prefix = "the Fn" uri = "HTTP: //java.sun. COM / JSP / JSTL / Functions "%>
<% @ taglib prefix =" Shiro "URI =" http://shiro.apache.org/tags "%>
<C: var = SET" CTX "value =" $ { } pageContext.request.contextPath "/>

JSP page referenced public page

<% @ include file =" /
static resource references, add the absolute path
<script src="${ctx}/statics/layui/layui.all.js"></script>
<link rel = "stylesheet" href = "$ {ctx} /statics/layui/css/layui.css"> 
in js files referenced by the page to be an absolute path using the EL expression $ {ctx}, now need the original jsp define variables to receive pages,
i.e., var ctx = $ {ctx};
last used directly in the variable document cited js
$.ajax({
type:"get",
url:ctx+"/exindustry/getTypeStatistics",
data:data,
dataType:"json",
error: function(request) {
layer.msg("操作失败!",{icon: 5,time:2000});
},
success :function (result) {

}
});







Guess you like

Origin www.cnblogs.com/yjava/p/11935646.html