Solved

General form question

Posted on 2002-04-30
4
173 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 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 77
Configure a Bean in an XML file 4 34
mysql jsp example issue 32 38
Java syntax, or is it Selenium 6 16
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

831 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