Solved

General form question

Posted on 2002-04-30
4
192 Views
Last Modified: 2010-03-31
Need advice on how best to implement a form with about 30 fields into a database.  I am just learning about servlets and beans and i am not sure if i should have jsp form call to a bean or to a servlet... or should i call to a servlet and then have it push to a bean.  At this point i started using a servlet but i have a sql execute statement that has 30 request.getParamters()...there must be an easier way...

0
Comment
Question by:menreeq
[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
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 6980462
First of all, a general design point: your users are going to be pretty pissed to be faced with a form with 30 fields on it. When I visit a site where I have to register, if it has more than ten required fields, I'm off somewhere else. Solution? Preferably use fewer fields, but if this can't be avoided, split it up into more than one form.

On a more technical note, look into JSP plus the Model View Controller design pattern (MVC).
0
 
LVL 35

Accepted Solution

by:
girionis earned 50 total points
ID: 6980468
 If you have 30 form fields in a form then you have to read them all one by one. The other thing you could do is to load all the parameters in a collection object and have a while loop that does the work for you:

Enumeration paramNames = request.getParameterNames();

while(paramNames.hasMoreElements())
{
    String paramName = (String)paramNames.nextElement();
    String[] paramValues = request.getParameterValues(paramName);
    ...
    ...
    ...
}

  With regards to your Servlet/JSP bean communication. What most people usually do is to have a JSP or a Servlet that talks to a bean which manages the database connection and the database interaction. So any database interaction the Servlet/JSP page wants to do is only done via the bean. Then the bean returns the ResultSet back to the Servlet/JSP.

  Hope it helps.
0
 
LVL 3

Expert Comment

by:jerelw
ID: 6981570
You're always going to have to "get" your parameters by name no matter what you do.

You can, however, name you parameters so that they are loop friendly like:

String value;
  int i = 1;
  while ((value = getParameter("LoopFriendlyParameter" + i))
                                             != null) {
    System.out.println ("Param" + i + ": " + value);
    i++;
  }  

0
 

Expert Comment

by:fundoosathish
ID: 6989645
what girionis had mentioned 'll work. 'm currently working on similar kind of project and this is the way it got to be.
what jerelw says also will work but this hangs some times.

bye
sathish
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:
Suggested Courses

631 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