jsp之${CTX}理解

jsp之${CTX}

根据自己的需要选择以下标签。

<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> 
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

我项目中的代码如下:
index.jsp

<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
    <title>主页</title>

    <script src="${ctx}/static/js/jquery.iphone.toggle.js"></script>
</head>

<body>
<div class="span10" id="content">
    <!-- start: Content -->

    <div>
        <ul class="breadcrumb">
            <li>
                <a href="${ctx}/index">主页</a>
            </li>
        </ul>
    </div>
    欢迎使用an笛声后台系统
</div>


<!-- end: Content -->
</div>
</body>
</html>

${CTX}
与${pageContext.request.contextPath}的对比

1、${pageContext.request.contextPath}是获取当前根目录。

2、${ctx}通过观察可以知道也是获取当前根目录的意思

不同之处:
${ctx}是
${pageContext.request.contextPath}的简写版。
同时发现在项目的index.jsp文件内有这样一段话的配置,<c:set var="ctx" value="${pageContext.request.contextPath}"/>。在此值得注意的是,在使用${ctx}的时候一定不要忘记把带有该配置的<c:set var="ctx" value="${pageContext.request.contextPath}"/>的文件引入到当前页面来。

关于${pageContext.request.contextPath}的理解,参考我转载并且修改之后的博文。
${pageContext.request.contextPath}的作用

该博文还参考了文章有:
http://blog.sina.com.cn/s/blog_6f0da7620100mrnt.html

  • 14
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值