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.
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.
Comments