• Post Reply Bookmark Topic Watch Topic
  • New Topic

how Jsp is different from Servlet

 
Rajesh Kesarwani
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
Please let me know that what is the difference between Servlet and Jsp.and
which one is superior.

Also let me know ,what Jsp can do,Servlet can also do and vice-versa,then
why we use both in the applications.and if anyone is superior then why we
read the other.

Also let me know that Jsp is first converted into servlet and then the
servlet is compiled and then executed.that means Jsp takes more time than
Servlet.so, if Jsp is superior then how.

Thanx in advance.

:roll:
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, there is nothing about superiority. We use the right technology to get the work done. Like hammer is for pounding nails and wrench is for twisting bolts/nuts.

You can search the same forum or JSP forum to find the differences/capabilities of both the technologies.

Thanks.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rajesh Kesarwani:
that means Jsp takes more time than Servlet.so, if Jsp is superior then how.


Both perform same, in terms of performance, in production environment. However, JSP is used to fabricate UI. And it will take less time in building UI in JSP than a servlet. Thus, it doesn't matter if it is first converted into servlet and then that servlet get compiled. JSP will save time when its about building UI.

For more google for Model2 architecture.

Thanks.
 
Sirish Kumar Gongal Reddy
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your Question is a wise Question.let me explain

1.Jsp follows Pagecompilation technique means it won't compile remember.
2.Jsp technology enables you, to mix reggular,static HTML with dynamically generated content from servlet.
3.Dynamicpart is written in java.
4.Better suite for complex application that reqires reusable components.
Hope that you are good at Servlets other wise if you have any questions plz feel free to add to our DashBoard.

Regards,
G Sirish Reddy.,
 
Anoop Kavalloor
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Is your left hand better or your right hand ? Comparing JSP and Servlets is similar to the above question. JSP is more of an HTML type page which means that JSP pages are viewed by the users. Servlet is/can also viewed by users but developers prefer servlet to write processing logic rather than content logic.
A JSP page, before it is served to the end user, is compiled into a servlet and then processed. But u can't term JSP as slow cos a JSP page can be precomplied and kept on the server before the first users asks for it.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Servlet looks like mostly Java that writes HTML, and a JSP looks like mostly HTML with some Java fragments. At runtime the container converts a JSP to servlet Java code. It turns all the HTML portion of the JSP page into string literals and writes them to the response, takes all the Java fragments in the JSP page and turns them into a regular Java class.

Being all Java, a servlet is better suited to doing complicated logic when a GET or POST request arrives at the server. Being mostly HTML, a JSP is better suited to building the next page.

A very common design has a servlet receive the request, call out to plain old Java objects to do some work, put the results into some JavaBeans, and forward to a JSP page. The JSP page is mostly HTML with little bits of code to extract data from the beans and merge it into the HTML.

JSPs support other cool technologies like tags. Some teams where I work have a rule of "no Java in JSPs" and find they can extract bean data and do conditionals and loops in page building just with tags. Having seen some of the evils of too much Java in JSPs I'm inclined to think this is a good rule.

Does that raise more questions?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!