Solved

Java Servlet - getting information from multiple textboxes

Posted on 2009-05-05
6
660 Views
Last Modified: 2012-05-06
Hi,

I am wondering if there is a way to pull data from multiple text fields on a html page without having to hardcode the textfield names into my code using getParamater(textboxnamehere).

For example my page has 4 text fields, I want to be able to get the informtaion in those text fields and run it through the same SQL statement individually, using a loop.

Basically while there is a textbox that has not been read get textbox information, run SQL statement then process the next textbox

instead of using code like
String textOne = request.getParameter("textfield");
String textTwo = request.getParameter("textfield2");
0
Comment
Question by:Robert
[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
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 450 total points
ID: 24311411
use the same name for each field and use

String[] values = request.getParameterValues("textfiald");
for (String value : values) {
    // make sql call

0
 

Expert Comment

by:Debasis126
ID: 24311707
Another useful way, while avoiding hardcoding is to use request.getParameterNames();

It will return an enumeration of all attribute names. Iterate through that and get all respective values for each parameter.

Hope this  helps.
0
 
LVL 92

Expert Comment

by:objects
ID: 24311713
the downside with using getParameterNames() is if you have other unrelated parameters in the query string

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Assisted Solution

by:Debasis126
Debasis126 earned 50 total points
ID: 24311730
String parameterName = "";
for(Enumeration e = request.getParameterNames();e.hasMoreElements(); )
{
                        parameterName = (String)e.nextElement();
                        String parameterValue = (String)request.getParameter(parameterName);
                               \\ insert your sql statements

}

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24311731
>>For example my page has 4 text fields, I want to be able to get the informtaion in those text fields and run it through the same SQL statement individually, using a loop.

You would get a more efficient solution if you put all four fields into a PreparedStatement and made one query
0
 
LVL 1

Author Closing Comment

by:Robert
ID: 31578335
Thanks all
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running JavaFX on JDeveloper 12C 1 77
Android development question 2 79
Java class and jar 3 42
dao vs facade design patterns 2 35
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

733 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