Complex jstl access hashmap objects.

Source: Internet
Author: User

When jstl accesses the objects in hashmap in the project, the general routine on the network cannot meet the requirements.

Generally

<%
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>

The above are relatively simple to use.

MeOfCodeRoughly as follows:

<%

..........

List li = call.exe cprocedure (OBJ, sendupdatefile. Class );
List <sendupdatefile>List = new arraylist <Sendupdatefile> ();
// Traverse the set
For (INT I = 0; I <li. Size (); I ++ ){
Sendupdatefile UI = (sendupdatefile) Li. Get (I );
List. Add (UI );
// System. Out. println (ui. tostring ());
}
Pagination P = new pagination ();
P. setindex (tmpcurrpage );
P. setpagesize (tmppagesize );
P. settotle (call. gettotle ());
P. setdata (list );
Request. setattribute ("Upfiles", P );

........

Hashmap <string, dealerbaseinf>List1 = new hashmap <string,Dealerbaseinf> ();
// Traverse the set
For (INT I = 0; I <li1.size (); I ++ ){
Dealerbaseinf UI = (dealerbaseinf) li1.get (I );
List1.put ("" + UI. GETID (), UI );
}
Request. setattribute ("Dealers", List1 );

%>

........

<TD size = "130px" align = "Left"> <select name = "delear" id = "delear"
Style = "width: 120px;">
<Option> select an upstream customer </option>
<C: foreach items ="$ {Dealers}"Var =" item ">
<Option value = "$ {item. Key}">$ {Item. value. name}</Option>
</C: foreach>
</SELECT> & nbsp; <font color = "red"> * </font>
</TD>

.........

<C: foreachItems = "$ {upfiles. Data}"Var ="Li">
<Tr>
<TD align = "center" class = "tab_r1"> <% = ++ I %> </TD>
<TD style = "" align = "center" width = "10%" class = "tab_r1"> <Input
Type = "checkbox" id = "rowid" name = "rowid" value = "$ {Li. ID}"/> </TD>
<TD align = "center" class = "tab_r1">
<C: Choose>
<C: When test = "$ {Li. delear> 0}">
$ {Dealers[Li. delear].Name}
</C: When>
<C: otherwise>
Invalid upstream customer
</C: otherwise>
</C: Choose>
<TD align = "Left" class = "tab_r1"> & nbsp ;$ {Li. filename} </TD>
<TD align = "center" class = "tab_r1" >$ {Li. ftpuptime} </TD>
<TD align = "center" class = "tab_r1" >$ {Li. disflag} </TD>
<TD align = "center" class = "tab_r1" >$ {Li. upoptor} </TD>
</Tr>
</C: foreach>

The following focuses on

1: <C: foreach items ="$ {Dealers}"Var =" item ">
<Option value = "$ {item. Key}">$ {Item. value. name}</Option>

2:$ {Dealers[Li. delear].Name}

Returned item. ValueThe dealerbaseinf object. Name is an attribute of dealerbaseinf.

Delear isThe FK external application key of the dealerbaseinf primary key.

$ {Dealers[Li. delear].Name} The expression is obtained based on the dynamically passed external reference key.

Corresponding name.

Idea Source

 
If you know the key, write $ {map. key} if the key is a variable, it is written as $ {map [Key]}, for example, map. put ("name", "Zhang San"); string tempval = "name"; $ {map. name }$ {map [tempval]}

Because the value in the [number can be dynamically changed], it is easy to obtain.

Because I am not familiar with jstl, I tested $ {dealers. $ Li. Dealer. name },
$ {Dealers [$ Li. Dealer]. name}, $ {dealers ["$ Li. Dealer"]. name}, both
No, of course, some of them are incorrect statements. test and test are correct.

It will be of great help in accessing complex jstl in the future.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.