简体   繁体   中英

How to receive value from multiply radio in struts2 Action

I am developing an online exam system that mainly include multiply choice.

  1. I used <input type='radio'/> to show some options in form. But I don't know how to receive the lots of options when click the button 'submit'.
  2. The datas from database have almost 100 items, and I have set pagination in show_questions_info.jsp , now every page show 3 questions and every question has 7 options.
  3. I want to use Action to receive value if it can be done. The <s:property value="question_code" /> is question number.

show_questions_info.jsp

 <%@ 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

  • 2018-11-06 add a item(3) for more information.

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)

   for(String questionCode:questionCodes){
     System.out.println(" For questionCode= "+questionCode+" selected option ="+request.getParameter(questionCode);):
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM