For example
<jsp:useBean id="total" class="java.util.LinkedHashMap"/>
// need somehow do something like this: total.put('key', 'value');
But without using scriptlets (it's obvious but a little bit ugly)
Inserting Elements Into a Java Map To add elements to a Map you call its put() method. Here are a few examples: Map<String, String> map = new HashMap<>(); map. put("key1", "element 1"); map.
The classic Java way is to pass the value Map as an argument to the constructor of Person and let person read the properties from the map. This way you can have multiple ways for constructing a Person object. Either by passing arguments directly, or passing the map.
The page directive is used to provide instructions to the container that pertain to the current JSP page. You may code the page directives anywhere in your JSP page. By convention, page directives are coded at the top of the JSP page. Following is the basic syntax of page directive − <%@ page attribute = "value" %>
You can use JSTL <c:set>
for this.
<jsp:useBean id="total" class="java.util.LinkedHashMap"/>
<c:set target="${total}" property="key" value="value" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With