我有一个表格,用于发送"问题"到服务器。
A&#34;问题&#34;有字段:标题,描述和选项(由<div id="TYPE_TEST" class="opclass">
<p><label for="option1"/>Option 1:
<input id="option1" name="key" type="text" placeholder=""/>
<input type="radio" name="value"/>
</p>
<p><label for="option2"/>Option 2:
<input id="option2" name="key" type="text" placeholder=""/>
<input type="radio" name="value"/>
</p>
<p><label for="option3"/>Option 3:
<input id="option3" name="key" type="text" placeholder=""/>
<input type="radio" name="value"/>
</p>
<p><label for="option4"/>Option 4:
<input id="option4" name="key" type="text" placeholder=""/>
<input type="radio" name="value"/>
</p>
</div>
表示的1到4)。 String - for option,Boolean - true / false。
那么,我如何创建每个选项的地图并将其发送到服务器?
{{1}}
谢谢你, 帕维尔
答案 0 :(得分:0)
你需要代表这样
代表像这样的问题和选项
//Map<question,options>
//where option also map
Map<String,Map<String,Boolean>> questions=new HashMap<String,Map<String,Boolean>>();
Map<String,Boolean> question1_options=new HashMap<String,Boolean>();
question1_options.put("option1",true);
question1_options.put("option2",false);
question1_options.put("option3",false);
question1_options.put("option4",false);
Map<String,Boolean> question2_options=new HashMap<String,Boolean>();
question2_options.put("option1",true);
question2_options.put("option2",false);
question2_options.put("option3",false);
question2_options.put("option4",false);
questions.put("question_1",question1_options);
questions.put("question_2",question2_options);
System.out.println(questions);
答案 1 :(得分:0)
遵循MaDHaN的代码:在JSP中,将其与<results>
<ready>yes</ready>
<student>
<accounts>****************</accounts>
<cardState>
<approved>true</approved>
<approvedacc>
<element>232323433233</element>
</approvedacc>
<refund>
<element>200</element>
</refund>
</cardState>
<cource>
<marks>
<element>A+</element>
</marks>
<total>
<element>20000</element>
</total>
</cource>
<created>true</created>
<firstName>john doe</firstName>
<ssn>123456</ssn>
</student>
</results>
一起使用。
如果有效,我认为MaDHaN值得接受。
答案 2 :(得分:0)
您可以通过多种方式完成此操作。其中一些如下:
<% Map<String,Boolean> map =new HashMap<String,Boolean>();
map.put("key1",true);
map.put("key2",false);
request.setAttribute("map", map);
%>
<%for(Map.Entry<String,Boolean> mapEntry: map.entrySet()){%>
<%= mapEntry.getKey() %>
<%= mapEntry.getValue() %>
<%}%>
或者
<c:forEach items="${map}" var="entry">
<c:out value ="${entry.key}" />
<c:out value ="${entry.value}"/>
</c:forEach>