JSP vs. Servlets

Discussion in 'Java' started by Sathyaish, Feb 9, 2007.

  1. Sathyaish

    Sathyaish Guest

    What are the pros and cons of using servlets instead of JSPs? As I
    understand from my sparse reading of the topic so far, they're both
    means of programming against the HTTP application model (i.e, request,
    session, response, HTTP Runtime etc.).
     
    Sathyaish, Feb 9, 2007
    #1
    1. Advertising

  2. Sathyaish

    senior Guest

    On Feb 9, 2:23 pm, "Sathyaish" <> wrote:
    > What are the pros and cons of using servlets instead of JSPs? As I
    > understand from my sparse reading of the topic so far, they're both
    > means of programming against the HTTP application model (i.e, request,
    > session, response, HTTP Runtime etc.).



    http://www.devx.com/tips/Tip/25217
     
    senior, Feb 9, 2007
    #2
    1. Advertising

  3. Sathyaish

    Lew Guest

    "Sathyaish" <> wrote:
    >> What are the pros and cons of using servlets instead of JSPs?


    senior wrote:
    > http://www.devx.com/tips/Tip/25217


    Broadly speaking, JSPs are for the layout, or "view" aspect of an application,
    and servlets are for the context and navigation, or "controller" aspect of an
    application.

    As the referenced tip suggests, JSPs look like HTML and servlets look like
    Java. It is more natural in a JSP to concentrate on artifacts like drop-down
    lists, submit buttons, headlines and the like. It is more natural in a servlet
    to concentrate on things like parsing a request for its parameters, forwarding
    the parameters to business and data logic, managing resource services,
    coordinating processes and forwarding the view to the next JSP.

    Both aspects of an application are required. Ideally, they will almost fully
    separate concerns. You should nearly never have scriptlet (Java code) in a JSP
    source file, nor response.out writes in a servlet .java source file.

    Check around for the "model-view-controller" (MVC) application model, what Sun
    calls the "Model 2 Architecture". It applies to Swing apps and other domains
    besides Web apps. It ties in with service architectures and portals, even.

    - Lew
     
    Lew, Feb 9, 2007
    #3
  4. Sathyaish

    Daniel Pitts Guest

    On Feb 9, 3:23 am, "Sathyaish" <> wrote:
    > What are the pros and cons of using servlets instead of JSPs? As I
    > understand from my sparse reading of the topic so far, they're both
    > means of programming against the HTTP application model (i.e, request,
    > session, response, HTTP Runtime etc.).



    A JSP is a different way to create a Servlet.
    The focus of JSPs are presentation. JSPs are great for creating HTML
    from a template.
    Pure servlets are great for business logic.

    A common approach is to have a Servlet that handles the business logic
    (I.E. a Controller), loads data to be rendered (I.E. Model) and passes
    that data to a JSP to be rendered (I.E. View)

    There are plenty of libraries that help you do this.
    Where I work we tend to use Spring Framework with Tiles.
     
    Daniel Pitts, Feb 9, 2007
    #4
    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. Peter Beck

    Threading - ASP. Net vs JSP/Servlets

    Peter Beck, Nov 19, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    733
    S. Justin Gengo
    Nov 19, 2003
  2. Mick
    Replies:
    0
    Views:
    446
  3. Prateeksha Web Services
    Replies:
    0
    Views:
    1,804
    Prateeksha Web Services
    Aug 29, 2003
  4. bigbinc
    Replies:
    1
    Views:
    711
    John C. Bollinger
    Nov 5, 2003
  5. Replies:
    0
    Views:
    4,442
Loading...

Share This Page