[英]How to receive value from multiply radio in struts2 Action
<input type='radio'/>
to show some options in form. <input type='radio'/>
来显示一些选项。 But I don't know how to receive the lots of options when click the button 'submit'. <s:property value="question_code" />
is question number. <s:property value="question_code" />
是问题编号。 <%@ taglib prefix="s" uri="/struts-tags" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <form action=""> <s:iterator value="questionInfoBeanList" > <table> <tr> <td><s:property value="question_code" /></td> <td><s:property value="content" /></td> </tr> </table> <table> <tr> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_A" />" id="1"> <lable for="1"><s:property value="op_type_A" /></lable> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_B" />" id="2"> <lable for="2"><s:property value="op_type_B" /></lable> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_C" />" id="3"> <lable for="3"><s:property value="op_type_C" /></lable> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_D" />" id="4"> <lable for="4"><s:property value="op_type_D" /></lable> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_E" />" id="5"> <lable for="5"><s:property value="op_type_E" /></lable> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_F" />" id="6"> <lable for="6"><s:property value="op_type_F" /></lable> <input type="radio" name="<s:property value="question_code" />" value="<s:property value="op_type_G" />" id="7"> <lable for="7"><s:property value="op_type_G" /></lable> </tr> </table> </s:iterator> <s:submit value="提交" /> </form> </html>
Edit history 编辑历史
Let's say you have reference of Questions List (displayed on JSP) in action class,simply iterate that list for questionCode(since in jsp <s:property value="question_code" />
is used for rendering q question) 假设您在动作类中引用了“问题列表”(显示在JSP上),只需对该列表进行迭代即可(因为jsp
<s:property value="question_code" />
用于呈现q问题)
for(String questionCode:questionCodes){
System.out.println(" For questionCode= "+questionCode+" selected option ="+request.getParameter(questionCode);):
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.