I take the Model 1 approach as well because of its relative simplicity and
amount of work that is done for you behind the scenes. I also ensure that
as little code as possible is placed into the .jsp pages themselves and is
instead put into Java Beans. So far, this approach has worked very well for
us (and is currently running a commercial ASP application on the Web).
Scott
> -----Original Message-----
> From: [EMAIL PROTECTED] [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, January 06, 2000 12:19 PM
> To: Drew Cox
> Subject: Re: web app programming specifications query
>
> Hi there,
>
> First, this email is in response to yours. But, I cant post to the
> jsp-interest group from work because my email address is different on this
> machine. Can you do me a favor and forward this to the group. Thanks.
>
> I have been doing some extensive talking with various authors on articles,
> books, and online chats with developers. I too have been reading about
> Model 1 and Model 2 approaches to use JSP, servlets, Javabeans, etc. I was
> worried because I read about Model 2, using the single servlet command
> setup which creates beans, populates their fields, then forwards to a JSP
> page which uses the bean to display the dynamic content the servlet stored
> in the bean. I am not doing our site like that. Instead, I follow the
> Model
> 1 a bit more, which as one author told me..its really a matter of opinion
> which you use. The model 1 dictates that your view AND controller in the
> MVC is JSP pages. That is, ALL requests first go to a JSP page, which uses
> a bean to do the logic and provide the dynamic content, that the JSP page
> then uses to display. The Model 2 uses the single servlet that uses a
> "hidden" form element (or is passed on with the request via the
> ?command=value) to "command" the servlet on what method to call, which in
> turn does what I said above..does the logic, creates a bean (or beans) to
> store the dynamic content the logic produces, and forwards to a JSP page
> to
> display it. As I see it, both do pretty much the same thing, but a bit
> differently. The Model 1 uses a JSP page as its starting point,
> instantiates a bean object (or more than 1 if the developer so desires),
> calls a method in the bean (usually passing the request and possibly the
> response object to the method, maybe named processRequest() ). That method
> uses the request object to populate various private fields via setter
> methods. With introspection, if a form data is passed, the setter methods
> that match the element names of the form are called to automatically set
> the properties of the JavaBean. Now..this is one of the areas I am not
> sure
> about..but I "think" the Model 2 approach does NOT do this. So, if it does
> not, then the JSP->JavaBean (Model 1) approach has a bit "easier"
> advantage
> there. If it does, well then they are even on that level. None the less,
> Model 1 has proven to be easier to implement and maintain (make changes,
> etc). The one thing I DONT do that Model 1 shows (in a few articles I
> read)
> is using a "controller" JSP page with lots of scriplet code in it. I use
> NO
> scriplet code except for the use of "conditional" scriplet code for
> various
> reasons (for example, to display some HTML if a given condition is met,
> otherwise display some other HTML), and the use of scriplet code to get
> the
> dynamic content.
>
> Now, something that may interest all, an author told me one thing to think
> about is that servlets, when handling multiple requests do NOT create
> multiple instances of the servlet...one for each request (storing it in
> the
> session). Instead, it is a thread context switch that occurs. This one
> item
> seems to be a performance gain in favor of the Model 2 approach. However,
> where I have my doubt is, when the servlet is called, it STILL has to
> create a bean that the JSP view page uses to display the content anyways.
> So I dont see this being such a performance gain myself. I think the
> difference lies in the scope of the javabeans in the Model 1 approach. If
> all javabeans are session scope, then they are created only once, and
> instances are instantiated from the first one in memory, which if I am
> correct, is faster than creating new objects on each request.
> Please..someone correct me if I am wrong on this as I am not quite clear
> on
> this matter. None the less, if beans are request or page scope, then each
> time that JSP page is accessed, a new bean object is created, populated
> and
> used by the JSP page, then freed. This "could" be a good thing in that the
> memory used by the bean is garbage collected after its use, whereas
> sessional beans stay alive for the duration of the session. But again I am
> not sure about this. Until more books come out to explain this stuff in
> more detail, I am relying on what I have read and some conversations I
> have
> had via email and irc.
>
> I am using the Model 1 approach because of its more simplistic
> implementation and maintenance. In my way of doing things, I use beans and
> JSP, no servlets (well, JSP = servlet..but I dont have to worry about the
> coding of the servlet). The beans are like components the way I am using
> them. One is used as a "client" bean that maintains the info of the client
> at all times (name, address, login name, password, etc) and can be updated
> at any time. Another is used to login with..its sole purpose is to log a
> client in. Another is to allow JSP pages send formatted email..they simply
> set the to, from, subject, message, bcc, cc and send it. I dont include
> ANY
> of this code on any jsp page. Now, the main thing I use scriplet code in
> is
> the use of a header and footer that EVERY page has. The header is the top
> menu bar that represents the products and various selections for those
> products. The footer is the text links to various parts of our site. In
> the
> header.inc file (its basically a jsp file but named .inc to make "more"
> sense of its use) I use various scriplet code for conditional purposes. If
> they are logged in, it displays a different menu setup. Same thing with
> the
> footer.inc. OTher than that, all pages just include the header and footer
> and do thier html stuff with some bean use thrown in to display dynamic
> content if need be.
>
> Thats my take on things. Sure would love to hear more on this topic from
> others doing similar development. Feel free to ask me any questions
> relating to this..I'll try to help in anyway I can as well. I am currently
> using Orion for development and IIS/JRUN for production (not my choice).
>
> Thanks..hope to hear from some of you.
>
>
> Kevin Duffey
> Software Engineer
> [EMAIL PROTECTED]
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html