Results 1 to 4 of 4
  1. #1
    deepika is offline Member
    Join Date
    Jan 2016
    Posts
    2
    Rep Power
    0

    Default Doubt in getting values of radio buttons in jsp page

    Hi ,


    I am working on online quiz project . I have retrieved all questions from mongodb and displayed in webpage . For options i have inserted html form with radio buttons where i can select the answer .

    Here is my sample code :

    int i=1;
    while(cur.hasNext())
    {
    //out.println(cur.next());
    BasicDBObject obj=(BasicDBObject)cur.next();
    question=obj.getString("Question").toString();
    option1=obj.getString("Option1").toString();
    option2=obj.getString("Option2").toString();
    option3=obj.getString("Option3").toString();
    option4=obj.getString("Option4").toString();
    answer=obj.getString("Answer").toString();
    out.println("Question : "+question);
    out.println("<br>");
    %>
    <form action="splitin js.jsp" method="post">
    <input type="radio" name="radio<%=i %>" value="0"><%=option1 %><br>
    <input type="radio" name="radio<%=i %>" value="1"><%=option2 %><br>
    <input type="radio" name="radio<%=i %>" value="2"><%=option3 %><br>
    <input type="radio" name="radio<%=i %>" value="3"><%=option4 %><br>

    <%
    }
    %>
    <input name="goto" type="submit" value="Submit" />
    </form>

    And in another jsp
    I have written code to get values of radio buttons

    String[] s=request.getParameterValues("radio");
    for(String lang:s)
    {
    out.println(s);
    }

    I am getting null pointer exception while clicking on submit button .
    Hope , you will help me to solve this issue .

    Thanks in Advance

    Deepika
    Reply With Quote Reply to Private Message Forward Message

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,930
    Rep Power
    22

    Default Re: Doubt in getting values of radio buttons in jsp page

    For starters you should not have Java code in a JSP page.
    It makes for very confusing code.

    The client browser should make a request targeting a servlet, which then sorts out the data required before forwarding to a JSP.
    The JSP then simply has to display it, using JSTL and EL.

    In any case, your button group is called "radio<i>" not simply "radio".
    And it looks like i is always 1?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    deepika is offline Member
    Join Date
    Jan 2016
    Posts
    2
    Rep Power
    0

    Default Re: Doubt in getting values of radio buttons in jsp page

    Please guide me how to get the selected radio button values from while loop to another jsp page

    Thanks in Advance
    Deepika

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,930
    Rep Power
    22

    Default Re: Doubt in getting values of radio buttons in jsp page

    I just said.
    You are getting the wrong parameter.
    Your radio buttons are not called "radio".
    Look at the source html in your browser and you'll see.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 9
    Last Post: 07-03-2015, 04:34 PM
  2. Radio buttons to open list of more radio buttons
    By mcconnelln89 in forum New To Java
    Replies: 1
    Last Post: 11-16-2013, 03:31 AM
  3. Help help.radio buttons
    By 10e5x in forum New To Java
    Replies: 3
    Last Post: 01-04-2011, 08:10 PM
  4. Help with Radio Buttons
    By miguelms19 in forum AWT / Swing
    Replies: 3
    Last Post: 06-29-2010, 07:49 PM
  5. How to use Radio Buttons
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •