Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets vs JSP

 
Sandipan Mukherjee
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are differences between Servlets and JSP?
please reply..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64711
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Sandy",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are used for generating Dynamic Web Content.

Main Difference is: Servlet can contain only Java Code but JSP can contain mixture of both html as well as Java Code.

Place the same question in google search box.
 
Ajay Vikas
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Even servlet can support HTML output to be displayed as JSP.
 
Vid Srini
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then main difference I feel is

1)user doesnt need to recompile the JSP files.Container takes care of it.Where as in case of SERVLET,user needs to recompile if any change is made to code and also he needs to restart the server.

2)Next is,Writing html code in Servlet is difficult.Because it has to be embedded inside Java and need to recompilation even for a small change.
In case of JSP,html tags are directly used.


Hope this gives answer to your question.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Even servlet can support HTML output to be displayed as JSP.


what would happen if you want to generate 1000 line HTML as a response?



2)Next is,Writing html code in Servlet is difficult.Because it has to be embedded inside Java and need to recompilation even for a small change.
In case of JSP,html tags are directly used.



If you modify JSP, it is even worse than servlet. why? before compilation it needs to go first translation process to convert to servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64711
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point shouldn't be which one automatically compiles, or which one needs to be translated, or any other behind-the-scenes technical details. Each of JSP and servlets has a distinct place in a web application. Using one when the other is appropriate just because of some implementation detail is not the way to create robust and well-designed applications.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64711
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question comes up often enough that I have added a new entry for it in the JSP FAQ.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have in fact never seen a well designed web application that didn't employ both (or at most replaced JSP with another display technology like XSLT or JSF).

I always wonder why so many people seem focussed on selecting a single magic bullet that will solve all their problems, instead of a combination of things that will do it so much better.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64711
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen T Wenting:
I always wonder why so many people seem focussed on selecting a single magic bullet that will solve all their problems, instead of a combination of things that will do it so much better.


I believe there are a number of reasons that we see so much of that:

Novice programmers that have learned one technology or the other (usually JSP) and use it exclusively since they aren't famililar with the other.

or

Programmers who makes decisions based upon specious factors such as "you don't have to compile JSPs" and use them exclusively just to get out of having to compile Java code.

or

Know-nothing CTO's or other people in power who don't bother to keep current and make rules that make no sense.

or

Those who just haven't learned any better yet.

We're doing our best to reach them all!
[ December 15, 2006: Message edited by: Bear Bibeault ]
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Were it just related to Java (or even IT) that would be the obvious list of reasons indeed.
But the same thing can be observed in every aspect of life.
Companies deciding to allow travel only using a single airline and hotel chain for example, even if other choices make more sense in many cases (sometimes cutting days, more often many hours, off of travel schedules).
People taking the car even if using a bus or train on a particular route makes more sense (I see that every day, commuting a route where the train is about 10% cheaper and 50% faster than the car yet droves take the car anyway).
Always watching the same TV channel, even if there are better ones for specific purposes (like a news channel to catch the news, or a dedicated movie channel that's showing your favourite movie that night while your preferred channel shows some soap opera rerun you've seen a dozen times already). My parents are somewhat like that, they're so focussed on the idea that German television is superior to Dutch that they'll watch a dubbed movie on a German channel and complain about the dubbing when that same movie is shown at the same time on a Dutch channel in the original with subtitles.
Or always shopping at the same store, even if another store has superior goods of some kind at a lower price and is right next door.

There must be more to it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic