Solved

General form question

Posted on 2002-04-30
4
152 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
Comment Utility
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
Comment Utility
 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now