Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

General form question

Posted on 2002-04-30
4
Medium Priority
?
201 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
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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

972 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