jsp中jstl标签库core全解析

本文详细解析了JSTL中的核心标签库,包括等标签的使用,通过实例介绍了各标签的属性和应用场景,帮助开发者更好地在JSP页面处理和展示数据。
摘要由CSDN通过智能技术生成

首先来认识一下jstl:

下面来介绍一下核心标签库:


前言:jstl是用来辅助el表达式,用来在jsp页面显示复杂结构的数据

一:<c:out value="" escapeXml="" default="">:

      查看c.tld可知:

 

<tag>
    <description>
        Like <%= ... >, but for expressions.
    </description> 
    <name>out</name>
    <tag-class>org.apache.taglibs.standard.tag.rt.core.OutTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <description>
Expression to be evaluated.
        </description>
        <name>value</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
        <description>
Default value if the resulting value is null.
        </description>
        <name>default</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
        <description>
Determines whether characters <,>,&,'," in the
resulting string should be converted to their
corresponding character entity codes. Default value is
true.
        </description>
        <name>escapeXml</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
  </tag>

         向界面输出value值(可输出特殊字符):

         属性解析:  value:  输出的值(el表达式,字符串)

                               escapeXml:是否将特殊字符转化,默认true

                               default: value值为null时输出

代码示例:

<%
       pageContext.setAttribute("name", "Tom");
       pageContext.setAttribute("name2", "<font color='red'>Tom</font>");
    %>
    
    <c:out value="${name2}" escapeXml="true"/><br/>
    ${name2}<br/>
out会将<>解析成&qt;&gt,这样保证界面原样输出,而一般的el表达式不转化<>,hyml会解析颜色

二:<c:set property="" scope="" target="" value="" var="">

 <tag>
    <description>
        Sets the result of an expression evaluation in a 'scope'
    </description>
    <name>set</name>
    <tag-class>org.apache.taglibs.standard.tag.rt.core.SetTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <description>
Name of the exported scoped variable to hold the value
specified in the action. The type of the scoped variable is
whatever type the value expression evaluates to.
        </description>
        <name>var</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
    <attribute>
        <description>
Expression to be evaluated.
        </description>
        <name>value</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
        <deferred-value>
	    <type>java.lang.Object</type>
        </deferred-value>
    </attribute>
    <attribute>
        <description>
Target object whose property will be set. Must evaluate to
a JavaBeans object with setter property property, or to a
java.util.Map object.
        </description>
        <name>target</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
        <description>
Name of the property to be set in the target object.
        </description>
        <name>property</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
        <description>
Scope for var.
        </description>
        <name>scope</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>
    设置属性:相当于setAttribute();

           属性搭配一: var:存储容器中的属性变量名

       

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值