Choice between JSP and Servlet

Discussion in 'Java' started by Matt, Jun 12, 2004.

  1. Matt

    Matt Guest

    I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
    eventually. But in application development's standpoint, anything can be
    done in servlet can also be done in JSP? Some people told me we can
    use the combination of both in one application.

    My question is in what situation we use JSP alone, servlet alone, or
    combination of both??

    Please advise. Thanks!!
     
    Matt, Jun 12, 2004
    #1
    1. Advertising

  2. Matt

    Sudsy Guest

    Matt wrote:
    > I am new to JSP and Servlet. I know JSP container will convert JSP to servlet
    > eventually. But in application development's standpoint, anything can be
    > done in servlet can also be done in JSP? Some people told me we can
    > use the combination of both in one application.
    >
    > My question is in what situation we use JSP alone, servlet alone, or
    > combination of both??


    Sure, you can incorporate Java code directly into a JSP. But it breaks
    one of the cardinal rules, and the reason for the existence of JSP in
    the first place.
    What you should be trying to do is cleanly separate Java code from
    HTML. Use tags in your JSP to access underlying functionality. Don't
    use servlets to generate HTML.
    Do yourself a favour and don't fall into the trap of trying to do it
    all in a JSP while promising that you'll separate things once you're
    ready to go live. You'll run out of time and maintenance will become
    an absolute nightmare!
    Do it right the first time.
     
    Sudsy, Jun 12, 2004
    #2
    1. Advertising

  3. On 11 Jun 2004 22:28:48 -0700, Matt <> wrote:

    > I am new to JSP and Servlet. I know JSP container will convert JSP to
    > servlet
    > eventually. But in application development's standpoint, anything can be
    > done in servlet can also be done in JSP? Some people told me we can
    > use the combination of both in one application.
    >
    > My question is in what situation we use JSP alone, servlet alone, or
    > combination of both??
    >
    > Please advise. Thanks!!


    The usual response to this question is:

    Use JSP where the complexity of the HTML is the most important
    thing / or where non-programmer HTML authors have to maintain the
    site.

    Use servlets where computation is the most important thing or
    where binary content such as images must be generated.

    Many people happily use a mixture.

    Bill

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/




    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    William Brogden, Jun 12, 2004
    #3
  4. Matt

    Liz Guest

    "Sudsy" <> wrote in message
    news:...
    > Matt wrote:
    > > I am new to JSP and Servlet. I know JSP container will convert JSP to

    servlet
    > > eventually. But in application development's standpoint, anything can be
    > > done in servlet can also be done in JSP? Some people told me we can
    > > use the combination of both in one application.
    > >
    > > My question is in what situation we use JSP alone, servlet alone, or
    > > combination of both??

    >
    > Sure, you can incorporate Java code directly into a JSP. But it breaks
    > one of the cardinal rules, and the reason for the existence of JSP in
    > the first place.
    > What you should be trying to do is cleanly separate Java code from
    > HTML. Use tags in your JSP to access underlying functionality. Don't
    > use servlets to generate HTML.
    > Do yourself a favour and don't fall into the trap of trying to do it
    > all in a JSP while promising that you'll separate things once you're
    > ready to go live. You'll run out of time and maintenance will become
    > an absolute nightmare!
    > Do it right the first time.
    >

    I'm new to jsp myself and am interested, therefore, as an observer.
    Is it true that the technique to do the separation is to make java beans?
    Then the jsp pages can interact with the java stuff via the bean properties?
     
    Liz, Jun 13, 2004
    #4
  5. Matt

    Sudsy Guest

    Liz wrote:
    <snip>
    >>Do it right the first time.
    >>

    >
    > I'm new to jsp myself and am interested, therefore, as an observer.
    > Is it true that the technique to do the separation is to make java beans?
    > Then the jsp pages can interact with the java stuff via the bean properties?


    That's the proper approach, IMHO. The tags (custom or Struts or JSTL)
    create scripting variables which adhere to the semantics of JavaBeans,
    i.e. they provide accessors/mutators named getXXX/setXXX (where XXX is
    the property name).
    Pay particular attention to the javax.servlet.jsp.tagext.TagExtraInfo
    class. Note that the norm is a tag similar to this:
    <taglibURI:tagName id="..." name="..." property="...">
    The bean specified by the name attribute is located and the getXXX
    method is invoked using the value of the property attribute to replace
    XXX. Finally, the returned Object is placed into page scope under the
    name specified by the id attribute.
    If you want to read an excellent treatise on the power of JSPs and
    custom tags then I highly recommend "Advanced JavaServer Pages" by
    David M. Geary, ISBN 0-13-030704-1. His region tag library was the
    progenitor of Tiles.
    Once you see how straight-forward it can be to "do it right", you'll
    steer clear of the quagmire of scriptlets and other nasties.
     
    Sudsy, Jun 13, 2004
    #5
  6. Matt

    juli Guest

    hai readers,

    I think servlets stuff should be learnt first since writing jsp alone will
    not make a web development scalable i mean u should embed custom tag from
    jsp in to servlets or servlets will looklike html pages wtih less coding
    ie programming logics.

    Once u get thru servlets +jsp deploy the same application in ejb it will
    be perfect scalable application
     
    juli, Jun 16, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mickey Segal
    Replies:
    0
    Views:
    913
    Mickey Segal
    Feb 2, 2004
  2. circuit_breaker
    Replies:
    2
    Views:
    2,045
    Jack Jia
    Apr 4, 2004
  3. Replies:
    0
    Views:
    4,438
  4. Replies:
    4
    Views:
    808
  5. miles.jg
    Replies:
    16
    Views:
    895
    Alf P. Steinbach
    Nov 14, 2007
Loading...

Share This Page