Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

General form question

Posted on 2002-04-30
4
Medium Priority
?
197 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 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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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