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:
- Get HashMap simple content with El expressions
- HashMap hm_simple_string = new HashMap ();
- Hm_simple_string.put ("Key1", "value1");
- Hm_simple_string.put ("Key2", "value2");
- Request.setattribute ("hm_simple_string", hm_simple_string);
In the JSP file:
- Get HashMap simple content with El Expressions:
- "${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:
- Take HashMap complex content with El expression
- HashMap Hm_complex = new HashMap ();
- Hm_complex.put ("Key1", Student_complex);
- Request.setattribute ("Hm_complex", Hm_complex);
HashMap is an instance of class classes.
In the JSP file:
- Take HashMap complex content with El expression
- <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