The Artima Developer Community
Sponsored Link

Java Answers Forum
An Array of Test Entry Boxes

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Wayne McKinstry

Posts: 1
Nickname: waynefrank
Registered: Oct, 2002

An Array of Test Entry Boxes Posted: Oct 2, 2002 1:49 PM
Reply to this message Reply
Advertisement
I am trying to make a servlet that has an array of text entry boxes for entering numbers. By changing numboxes, I would be able to vary the number of boxes. The problem is that it is only finding the first occurrence of the text entry boxes.

If the idea of an array of text entry boxes is totally stupid, feel free to say that as well, as well as any suggestions as to a better basic approach. Thanks!

To run my servlet:

http://www.mycgiserver.com/servlet/waynefrank.ManyAverageServlet1

The whole servlet:

package waynefrank;
//** Computes an average of many numbers input by the user
//** ManyAverageServlet1.java
import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.*;
import java.util.*;
import javax.swing.*;
//imported for buttons, labels, and images
import java.awt.*;
//imported for layout manager
public class ManyAverageServlet1 extends HttpServlet
{
// numboxes is the number of number-entry boxes we have.
double numboxes = 04;
String ctrCharValue = null;
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Enumeration flds = req.getParameterNames();
if (!flds.hasMoreElements()) {
//*** No form submitted -- create one:
out.print("<form method=\"POST\"" + " action=\"http://www.mycgiserver.com/servlet/waynefrank.ManyAverageServlet1\"> ;");
out.print("<font face=arial>");
out.print("** Please enter numbers that you want to average. **");
out.print("<br><br>");
// xxxxxxx put processing to form text boxes
for( int ctr = 1; ctr <= numboxes; ctr++) {

// ???????
out.print("<td><input name= '+ numbox[ctr] +' size=17></td>");
out.print("<br>");

}


// put out buttons
out.print("<input type=submit name=sobmit value=Compute><br><br>");
out.print("<input type=reset name=sobmit value=Clear><br><br>");
out.print("Press the Compute button to get the average");
out.print("</font>");
// end of putting out form

out.println("</form></html>");

// Process events from page
} else {
double average;
String[] NumEntered = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,nul l,null,null,null,null,null,};
double[] numin = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,};
String ACTION;
ACTION = req.getParameter( "sobmit" );

if( ACTION.equals( "Compute" ) )
// xxxxxxx text box processing
{
try {
average = 0;
out.print("<font face=arial>");
for( int ctr = 1; ctr <= numboxes; ctr++) {

// ???????
NumEntered[ctr] = req.getParameter("+ numbox[ctr] +");

numin[ctr] = Double.parseDouble((String) NumEntered[ctr]);

out.print("Number "+ctr+"= "+NumEntered[ctr]);

out.print("<br>");

average = average + numin[ctr];

}

average = average / numboxes;
out.print("<br>");
out.print("Average= "+average);
out.print("</font>");

} catch(NumberFormatException e) {
out.print("<img src=http://www.mycgiserver.com/~waynefrank/katie.jpg>");
out.print("<font face=arial>");
out.print("<br><br>Even Katie knows you have to enter numbers !! ");
out.print("Use the browser back button and try again. :)");
out.print("</font>");
}
}
} out.close();
} } ///:~ end of servlet

Topic: Getting Text from JTExtPane Previous Topic   Next Topic Topic: help: HTTP method POST is not supported by this URL

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use