How Can we show One Key and its Values from Map<String, List<Object>> at a time on a JSP page?

Vipul

I am making a Quiz Project in which I want show One Question and it's respective options at a time. I have created a DB and by using HQL I have brought that data on to the JSP page. I have put that data in MAP. I am iterating the map using entrySet. Right now I am able to show all Questions and it's Options on a JSP page, but I want to show one question and it's options at a time and on clicking of a NEXT button I want to show the next Question and it's options and so on.

My Code On Jsp Page is:

<%
Map<String, List<Answers>> map = new HashMap<String, List<Answers>>();
map = (Map)session.getAttribute("questAndAns");

%>  

<%
for(Map.Entry<String,List<Answers>> entry : map.entrySet())
{
%>
<br>
<%
List list =  entry.getValue(); 
if(list != null && list.size() > 0)
for(int i = 0 ; i < list.size(); i++)
{
 Answers answers =(Answers) list.get(i);
%>
<%= answers.getAnswer() %>

String in Map contains a question and List are the options of that particular Question. How can I achieve it?

Help Appreciated. Thanks in advance.

Gurwinder Singh

You can use map.keySet() to get all the questions. Then use map.get(key) to get list of options for it.

Set<String> questions = map.keyset();
for(String q : questions) {
    List<Answers> answers = map.get(q);
    . . . 
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to iterate a List<Map<String,String>> and add its key,values in a Java Object

Python: How to map values from list to its related dictionary key

How I can get map on JSP page age and show the key and value in two columns of a table

get key from Map<String,List<String>> knowing one of the List values

Get Map<String, List<Object>> from List<Object> where the key is one of the fields of the objects

How to retrieve a key from the Map<String,List<String>> based on its value (an element of a list)?

How can we pass list object from jsp to struts2 action?

How we can show one product from each subcategory in product page

Can we redirect one jsp page to another jsp page

Change the key of an object with one attribute from its values

Removing values from a List<Object> that is part of a Map<String,List<Object>>

How can we map a c# complex list object from FormData in MVC through Jquery

Create a map with values of one map as key and values of each map as values from a list of maps

How can we access the Child Key from Object

how to filter and transform a List<Map<String,object>> in to new List<Map<String,object>> with different key value

How do we get string values from javascript object?

How can I use dictionary to map keys located in one string list to values located in another string list using C#?

Prepare map of list with values from object where key is value from list inside this object

How can an object get its key from a HashMap?

How to get only one value from hashmap which contains key String, and list<Object>

How to create a HashMap that would have String as key and the value would be another HashMap from one list of custom object?

How can I extract key-values from one-level JSON string using regex?

How to show values from map or list made in controller class with Phoenix

How to pass the values from one jsp page to another jsp without submit button?

Convert in java List<POJO> to Map<String, List<Object>> where the key is a field name and value is a list of values by field

How to map get values by dynamic key from array of object?

How to show the first value of dropdown list always on JSP for the first time when page is loaded?

How can I not show the undefined values from map() return

Cypress- How can we list key names under certain key (not values of these keys)