Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java Servlet - getting information from multiple textboxes

Posted on 2009-05-05
6
Medium Priority
?
727 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 1800 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Assisted Solution

by:Debasis126
Debasis126 earned 200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

604 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