?
Solved

Servlets - Radio button check uncheck validation?

Posted on 2000-05-16
3
Medium Priority
?
600 Views
Last Modified: 2013-11-24
Hello friends over this media! ,

I am stuck here with a servlet in which i am trying to generate a online quiz . I genearated radio buttons dynamically depending on the data from the database.i.e., there's a table which has 5 columns namely, question, choice1,choice2,  choice3,choice4. I am able to generate the buttons but am not able to read the value of the checked radio button. Though the default button is checked it's still not printing the value. I  have the HTML code inside this servlet itself. I have'nt written it separately because i have to generate radio buttons depending on the number of rows in the database. Please help me out....:-(! Here 's the code attached!

/***** part of dopost method**********/
/*Am using a MsqlJava package to connect and retrieve data from the
database. ***/
/***qans is the table ******/
public void doPost(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {    

String row1[],row2[],row3[],row4[],row5[];

MsqlResult result1=msql.Query("select question from qans");
MsqlResult result2=msql.Query("select answer1 from qans");
MsqlResult result3=msql.Query("select answer2 from qans");
MsqlResult result4=msql.Query("select answer3 from qans");
MsqlResult result5=msql.Query("select answer4 from qans");

/***Just checking for one row fetched from the database*****/
if ((row1 = result1.FetchRow()) != null && (row2 = result2.FetchRow()) != null && (row3 = result3.FetchRow()) != null && (row4 = result4.FetchRow()) != null && (row5 = result5.FetchRow()) != null)
            {
            for(i=0; i < row1.length; i++)
            for(j=0; j < row2.length; j++)
            for(k=0; k < row3.length; k++)
            for(l=0; l < row4.length; l++)
            for(m=0; m < row5.length; m++)

toClient.println("<font size=3 color=navy>" + row1[i] + "<BR><BR><INPUT TYPE=RADIO NAME=" + a[inc] + " VALUE=" + row2[j] + " checked >" + row2[j] + "<BR><INPUT TYPE=RADIO NAME=" + a[inc] + " VALUE=" + row3[k] + ">" + row3[k] + "<BR><INPUT TYPE=RADIO NAME=" + a[inc] + " VALUE=" + row4[l] + ">" + row4[l] + "<BR><INPUT TYPE=RADIO NAME=" + a[inc] + " VALUE=" + row5[m] + ">" + row5[m] +"</font><br><br>");

      String value = request.getParameter("a[inc]");
                    toClient.println(value);
/**********Prints a null value when run**************/
            inc++;
            }
      
}
0
Comment
Question by:smithan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Expert Comment

by:sgoms
ID: 2815017
Seperate your logic..
/**GenerateServlet.java**/
have the servlet generate the form dynamically
in the form action method call a servlet called 'ProcessDataServlet' in that process ur answers.

GenerateHTMLServlet
->
<FORM NAME=Quiz ACTION="/servlet/ProcessDataServlet">
....

->
/**ProcessDataServlet.java**/
public void doPost(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {    
  String ans=request.getParameter("Radio button name");

}


you cannot have the checking in the same method 'cos once the HTML response is sent to the browser the html page has to contact the servlet again for the data to be processed.
-sgoms
0
 

Author Comment

by:smithan
ID: 2823174
thanks a lot sgoms! It works now!
0
 
LVL 5

Accepted Solution

by:
sgoms earned 400 total points
ID: 2823241
kewl..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question