Research of JSTL - part of experiment

类别:Java 点击:0 评论:0 推荐:

Research of JSTL - part of experiment

 

1.        Assign to a value and test by itself:

<c:set value="${customers}" var="xxxx" scope="page"/>

<c:if test="${xxxx!=null}">

<c:remove var="xxxx"/>

 

2.        To judge a attribute or object and if it’s a null or null string

<c:if test="${customer.address.line2!=null && customer.address.line2!=''}">

  ,<c:out value="${customer.address.line2}"/>

</c:if>

 

3.        Setting a value then for control operation using condition of the If in the ForEach

<c:forEach var="item" begin="1" end="10">

   <c:set var="isLess5" value="${item<5}"/>

   <c:if test="${isLess5}"><font color="red"></c:if>

   <c:out value="${item}"/>

   <c:if test="${isLess5}"></font></c:if>

   <br/>

</c:forEach>

 

4.        To set a attribut in whatever using Request,Session or Application,but only the Application can impact the ServletContextAttributeListener

<%session.setAttribute("key","fff");%>

you can access it using method,below:

<c:out value="${key}"/>

 

5.        How can you do when the web.xml have mutli-Listener

<web-app>

  <listener>

    <listener-class>com.server.InitListener</listener-class>

  </listener>

  <listener>

    <listener-class>com.server.AttributeListener</listener-class>

  </listener>

 

6.        Using JSTL create a collection

<%--

please adds this code

<c_rt:set var="tests" value="<%=new java.util.HashMap()%>"/>

--%>

<%request.setAttribute("tests",new java.util.HashMap());%>

 

7.        Setting the property,target and assign to a collection

<c:set var="name" value="Micro"/>

<c:set target="${tests}" property="name">

  Hi <c:out value="${name}"/>

  <br/>

  <%="&nbsp;&nbsp;I'm not available."%>

</c:set>

<c:set value="I love you" target="${tests}" property="ccccc"/>

<c:set value="I love you1" target="${tests}" property="ddddd"/>

 

 

8.        To test and out the collection (include escapeXml method)

<c:out value="${tests.length}"/>

You didn't get the value using this method.

<c:forEach items="${tests}" var="test" varStatus="status">

<br/>

<c:out value="${status.count}"/>

{<c:out value="${status.index}"/>}

:

<c:out value="${test.value}" escapeXml="false"/>

</c:forEach>

 

<c:remove var="tests"/>

 

<!--  the results  -->

You didn't get the value using this method.
1 {0} : I love you
2 {1} : I love you1
3 {2} : Hi Micro
  I'm not available. Maurice:Richard

 

9.        What do you need for using Xml target in jdk1.4

Jaxen-full.jar

Jaxp-api.jar

 

10.    What do you need for using Sql target

Jdbc2_0-stdext.jar

 

<x:parse var="a" >

<?xml version="1.0" encoding="GBK"?>

  <a>

   <b><c>{中国人}</c></b>

   <d>bar</d>

  </a>

</x:parse>

 

<c:out value="${a}"/>

<x:out select="$a//c"/>

<x:out select="$a/a/d"/>

<!--  the results  -->

[#document: null] {ÖйúÈË} bar

 

11.    To note have different results

Don’t out: <c:import url="response.xml" var="ccc"/>

Out: <c:import url="response.xml" />

 

12.    Use xml from a importing xml

<%@ taglib prefix="xm" uri="http://java.sun.com/jstl/xml" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

 

<c:import url="response.xml" var="ccc"/>

<xm:parse var="data" xml="${ccc}"/>

<c:out value="${data}"/>

<xm:out select="$data//*"/>

 

 

 

本文地址:http://com.8s8s.com/it/it16114.htm