File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes jsp versus servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp versus servlets" Watch "jsp versus servlets" New topic

jsp versus servlets

Nidhi Jain
Ranch Hand

Joined: Mar 26, 2006
Posts: 31

Can anybody tell me the detailed diffrence between jsp and servlets.I only know that after complied jsp will trun into servlets.but that' not a diffrence.

Girish Solanke

Joined: Mar 03, 2006
Posts: 13

As far as my knowledge is concern,

Servlet & JSP are act as servlet itself,

But basic difference between them is
Use JSP when you have more Presentation logic than Bussiness logic
Use Servlet when you have more Business logic than Presentation logic

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Think of JSP as an extension of servlets; specifically designed for formatting a textual response (HTML, etc...).

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Functionally, you could say Servlets and JSPs are the same. They both are compiled and run as Servlets on the JVM. Pretty much anything you can do in a Servlet, you can do in a JSP.

Having said that, JSPs are obviously designed to serve markup to the client, but it HTML, HTML, XML or WML. They are easy to manipulate in a builder tool. Servlets typically defer to a JSP for markup generation.

Servlets are all about the Java. You can write all sorts of control code in a Servlet. A Servlet typically handles an incoming request, and figures out how to handle that incoming request, which usually involves validation, calling on JavaBeans and EJBs, and as I mentioned, deferring to a JSP for markup generation.

JSPs are mostly HTML with a little bit of Java in them. Servlets are largely Java, with the occassional and rare bit of HTML. Someone more clever than me once remarked that "JSPs are just Servlets turned inside out."

I've got a bit more on how Servlets and JSPs fit into MVC on my website. Here's the link:
I agree. Here's the link:
subject: jsp versus servlets
jQuery in Action, 3rd edition