An online jewelry retailer wishes to customize their online catalog for users who are logged in. They went to show specials for the user's brithstone month. The company's special offers are stored as a Map<String, Special> identified as specials in application scope.
There is a bean stored as a session-scoped attribute named userInfo. Calling getBirthdate().getMonth() on this bean will return the user's birthsone month.
Which of the following code snippets could correctly retrieve the appropriate special offerings?
I assume sc on line 17 of the second-to-last listing is the ServletContext, right? I think the problem may be that you're storing specials under the key "1" (a String), but trying to retrieve it with the key 1 (an Integer). A little debugging would probably let you see if the Map "specials" is actually stored in the application scope, and what exactly it contains.
posted 3 years ago
Hi, I modified my code:
The relevant EL in the jsp is:
The output printed is:
Special Map: [Lmurach.business.Special;@7cba55c5
Good, that's progress! It's not totally clear to me if you're just showing that the change worked, or if you're still confused by this output. Assuming you're still confused, what you're seeing there is the "toString()" representation of the array of Specials stored in the Map under the key "1". Of course, that's not what you'd want to appear on your web page in real life. It's more likely that you'd want to display the individual offers. In that case, you'd need to iterate though the array using something like JSTL's c:forEach tag, and then get the offers for each element of the array. Something like:
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database