Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's the different between JSP and servlet

 
ellen berry
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys:
right now I am learning JSP and Java Servlet. but I have some confuse that JSP and servlet can do the same things? or they do different function in some sepcific areas. what's the different?

ellen
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are used like HTML markup using special JSP tags, but generating dynamic (versus static) content.
Servlets extend the functionality of a server and are used to prepare javabeans for JSPs to use. Servlets are the controller and JSPs are the view.
That's a very short explanation but the best way is to read books and/or on line articles on the subject and then practice with an app server which you can easily install in your PC.
 
Dmitriy Pavlyuk
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easy difference is that
using JSP you insert calls the class into markup (html tag) but
using Servlet you insert tag into class code.
Using JSP you divide the presentation and bisness logic. Servers which allow JSP automatically create servlets from jsp pages.
 
Kai Middleton
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an answer a fellow programmer of mine had:
Well JSP actually turns into a servlet the first time it is accessed. I discussed this recently with my colleagues and basically it seems cleaner to use JSP with tag libraries to generate XML than to do stuff with servlets.
Anyway you slice it, it is still compiled Java anyway. But JSP allows you to mix and match content, images, style sheets in the same directory with the JSP so you can easily refer to it. And it seems easier for people to figure out where to go to debug when they can just see a URL that matches the path in their directory.
Another small benefit is that when you change a JSP you don't have to cycle the service it automatically gets recompiled and loaded in, so this is nice.
JSP tag libraries give you a nice way to build and reuse code modules as well. There are other niceties that JSP's give you but the above features are some of the more important things.
There is not much difference between using JSP and servlets other than the above but these small things make it a little nicer than just servlets.

[This message has been edited by Kai Middleton (edited August 01, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic