Thanks to all for there responses.

Matthias:

I can see your point and it is interesting indeed. Basically
instead of using one Servlet you combine all the processes
into one servlet and have each form utilize that servlet
.... hmm very interesting. I will go with that. Thanks!

Ryan




-----Original Message-----
From:    Matthias Carlsson
[EMAIL PROTECTED]
Sent:    Mon, 11 Sep 2000 19:07:28 +0200
To:      [EMAIL PROTECTED],
[EMAIL PROTECTED]
Subject: SV: Design Question


Although I don't know if it is an effective approach, this
is how I
(usually) solve this kind of problems (and since I'm used to
it, I
find it effective).

Since I don't like having lots of classes, I create one
servlet, say
FormHandler. When I call this servlet, I also include a
parameter
telling me which form it was called from. This check is done
in it's
doPost method, and the correct doPost is then called. See
example
below:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FormHandler extends HttpServlet {

        public void doPost(HttpServletRequest request,
HttpServletResponse
response)
        throws ServletException, IOException {

                String caller = request.getParameter("caller");
                if (caller.equals("form1")) doPostForm1(request,
response);
                else if (caller.requals("form2")) doPostForm2(request,
response);
                ... and so on

        }

        private void doPostForm1(HttpServletRequest request,
HttpServletResponse
response)
        throws ServletException, IOException {
                // handle form data sent from 'form1'
        }

        private void doPostForm2(HttpServletRequest request,
HttpServletResponse
response)
        throws ServletException, IOException {
                // handle form data sent from 'from'
        }

}

This way, you can easily add new forms to be handled to the
servlet, and you
won't
have to keep track of several source files, and their class
names.
Hope this helps.

[ Matthias Carlsson ]
[ Programmer (Java, CGI/Perl, Javascript, HTML) ] [ Web
Designer ]
[ E-Mail : [EMAIL PROTECTED] ] [ ICQ:
1430647 ]

-----Ursprungligt meddelande-----
Fran: A mailing list for discussion about Sun Microsystem's
Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]For
Ryan Richards
Skickat: den 11 september 2000 15:43
Till: [EMAIL PROTECTED]
Amne: Design Question


I have a web site that uses several servlets to capture and
utilize html form data and extract or insert into a database
based on the form etc...Each form has it's own servlet that
does the functionality. The only difference between them is
of course th form elements and the jdbc queries/operations.

My question is this: Should I be looking at a specific
design pattern or some other means to get away from using a
specific servlet for EVERY html form? I feel like I am doing
a half-baked approach here and would appreciate any
ideas/comments/etc..


Ryan
___________________________________________________________________________
Visit http://www.visto.com/info, your free web-based
communications center.
Visto.com. Life on the Dot.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body
of the message "signoff SERVLET-INTEREST".

Archives:
http://archives.java.sun.com/archives/servlet-interest.html
Resources:
http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html






___________________________________________________________________________
Visit http://www.visto.com/info, your free web-based communications center.
Visto.com. Life on the Dot.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to