For MAP access using jstl, the key is integer or long.

Source: Internet
Author: User

 

Refer to this article on stackoverflows.ArticleHttp://stackoverflow.com/questions/924451/jstl-access-a-map-value-by-key

 

Map <integer, string> map = new hashmap <integer, string> (); <br/> map. put (1, "one"); <br/> map. put (2, "two"); <br/> <C: Out value = "$ {map [1]}"/>The value cannot be obtained.

 

ChangeMap <long, string> map = new hashmap <long, string> (); <br/> map. Put (1l, "one ");That is, it is normal.

 

The reason is that jstl encapsulates numbers as long by default.

 

Another problem: type conversion

 

 

Map <long, string> map = new hashmap <long, string> ();

$ {Map [obj. ID]}

 

When obj. ID is defined as int type, the value cannot be obtained. Convert obj. ID to long.

On the JSP page, you can write

$ {Map [obj. ID + 0]} 

 

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.