| Note: jsp1.2 is not supported in Weblogic8.1, so jstl1.0. 1. Tag reference in JSP is as follows: <% @ Taglib uri = "http://java.sun.com/jstl/core" prefix = "C" %> Note that this reference is different from the reference method in Tomcat. the reference method in Tomcat is as follows: <% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "C" %> 2. Take out the jsp-api.jar from Tomcat's common/lib/and put it under the WebLogic application Lib. 3. the header declaration must specify pageencodeing, for example: <% @ Page contenttype = "text/html; charset = GBK" pageencoding = "GBK" Language = "Java" %> 4. encoding must also be specified in Web. xml; otherwise, Chinese characters are not supported. <Context-param> <Param-Name> weblogic. jsp. Encoding </param-Name> <Param-value> GBK </param-value> </Context-param> 5. The above configuration can use jstl, but not all labels, such as fn. Another point is that El expressions cannot be used independently. You must use <C: Out value = "$ {}"/>. |
Bytes -----------------------------------------------------------------------------------------------------------
Handling Java. util. Map and nested list in jstl el
In El, square brackets are used to retrieve elements of arrays and collections. For a set that implements the java. util. map interface, the square brackets operator uses the associated key to find the value stored in the ing. Specify the key in square brackets and return the corresponding value as the expression value. For example, expression $ {map ['key']} returns the value associated with the "key" key in the Map referenced by the map identifier.
When the expression value in the items attribute of foreach is Java. util. MAP, the type of the variable named IN VaR is Java. util. Map. Entry. If Var = entry, use the expression $ {entry. Key} to get the key name. Use $ {entry. Value} to get the value of each entry. This is because java. util. Map. entry objects have the getkey and getvalue methods. The expression language complies with the naming conventions of JavaBean.
<%
Map <string, string> MAP2 = new hashmap ();
Map2.put ("A", "Hello World ");
Map2.put ("B", "this is map ");
Request. setattribute ("MAP2", MAP2 );
%>
<Br>
Key-Value Pair traversal <br>
<C: foreach Var = "item" items = "$ {MAP2}">
$ {Item. Key }>$ {item. Value} <br>
</C: foreach>
Key traversal <br>
<C: foreach Var = "item" items = "$ {MAP2}">
$ {Item. Key} <br>
</C: foreach>
Value traversal <br>
<C: foreach Var = "item" items = "$ {MAP2}">
$ {Item. Value} <br>
</C: foreach>
<Body>
<Br>
<%
List <string> List = new arraylist <string> ();
List. Add ("first ");
List. Add ("second ");
List <string> list2 = new arraylist <string> ();
List2.add ("aaaaaa ");
List2.add ("bbbbbb ");
Map <string, list <string> map = new hashmap ();
Map. Put ("A", list );
Map. Put ("B", list2 );
Request. setattribute ("map", MAP );
%>
Obtain the list value through the key and traverse the list <br>
<C: foreach Var = "item" items = "$ {map ['a']}">
$ {Item} <br>
</C: foreach> <br>
<C: foreach Var = "item" items = "$ {map ['B']}">
$ {Item} <br>
</C: foreach> <br>
The value in the map is the list, and each item in the list is directly traversed. <br>
<C: foreach Var = "item" items = "$ {map}">
<C: foreach items = "$ {item. Value}" Var = "it">
$ {It} <br>
</C: foreach>
</C: foreach> <br>