您的位置:首页 > 产品设计 > UI/UE

${pageContext.request.contextPath}和${ctx}

2017-04-18 15:13 363 查看
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> -----------jstl标签的库引用的声明

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<c:set var="ctx" value="${pageContext.request.contextPath}" />-----------项目的根目录   :

在使用的时候可以使用${pageContext.request.contextPath},也同时可以使用<%=request.getContextPath()%>达到同样的效果,同时,也可以将${pageContext.request.contextPath},放入一个JSP文件中,将用C:set放入一个变量中,然后在用的时候用EL表达式取出来。  

引用路径:

<link href="${ctx}/assets/css/font-awesome.css" rel="stylesheet" />

<link href="${ctx}/assets/css/bootstrap.css" rel="stylesheet" />

<link href="${ctx}/css/common.css" rel="stylesheet" />

<link href="${ctx}/assets/css/checkbox3.min.css" rel="stylesheet">

<script src="${ctx}/lib/jquery/jquery-1.11.1.min.js"
type="text/javascript"></script>

<script src="${ctx}/assets/js/bootstrap.min.js"></script>

form中的路径:<form name="searchForm" method="post" action="${ctx}/product/product">

onlick中跳转路径:<input type="button" value="编辑" onclick="window.location.href='${ctx}/product/editProduct?method=edit&goods_id=${item.goods_id}&thisPage=${pageNum }';"class="button1" style="display: none;" />

ajax中的请求路径:$.post('${ctx}/product/checkSetNameExist',{"set_name":setName},function(data){
if (data!=null && data.length>0){
alert("商品集名称已经存在,请重新输入!");
$('input[name=set_name]').focus();
return;

});

${pageContext.request.contextPath}是从这个请求路径(URL)上截取你的项目应用名的,比如请求url是http//:localhost:8080/hello,你的项目名是hello,截取的结果应该就是/hello,/代表http//:localhost:8080。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: