The JSP page uses El to get the corresponding value in the map by pressing key

Source: Internet
Author: User

The JSP page uses El to get the corresponding value in the map by pressing key


Go to: "jsp page use El to get the corresponding value in map by key " Address: http://blog.csdn.net/baple/article/details/18517359


Code in the JSP page:
<script type= "Text/javascript" >
var msgtip = "${msgs[' LoginError '}";
alert (Msgtip);
</script>

Precautions:

Do not add to the map name, Direct is []

Key to use single quotation marks

In JS, to add double quotes outside the entire value


Add:

10.10 Using jstl tags and el expressions to display the value of a string in HashMap

In the servlet file:

    1. Get HashMap simple content with El expressions
    2. HashMap hm_simple_string = new HashMap ();
    3. Hm_simple_string.put ("Key1", "value1");
    4. Hm_simple_string.put ("Key2", "value2");
    5. Request.setattribute ("hm_simple_string", hm_simple_string);

In the JSP file:

    1. Get HashMap simple content with El Expressions:
    2. "${hm_simple_string[' Key1 '}" >

In the JSP file, Hm_simple_string is a HashMap instance, and map is a data structure paired with the value of the key key. The value is displayed by key, so that the value corresponding to the specified key can be displayed directly using [' Key_name '].

The results shown are:

Get HashMap simple content with El expressions value1


10.11 using jstl tags and el expressions to display the values of bean properties in HashMap

In the servlet file:

    1. Take HashMap complex content with El expression
    2. HashMap Hm_complex = new HashMap ();
    3. Hm_complex.put ("Key1", Student_complex);
    4. Request.setattribute ("Hm_complex", Hm_complex);

HashMap is an instance of class classes.

In the JSP file:

    1. Take HashMap complex content with El expression
    2. <c:out value="${hm_complex[' key1 ' [' username ']}" ></c:out>

Hm_complex is a hashmap type that can be obtained by key. But value is a bean type, so it is necessary to get the value of the specified key by [' Key1 '], and then to access the Bean's Username property by [' username '] and display it.

The results shown are:

Take HashMap complex content via El expression: Student_complex

The JSP page uses El to get the corresponding value in the map by pressing key

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.