az said:
Anyone can tell me what is the difference between JSP and Servlet?
Thanks a lot!
Servlets are written in pure Java. Requests for a web page go to a Java
program.
JSP's are HTML pages with some Java hacked into them. They are neither
pure HTML nor pure Java. It is a more limited and hybrid environment.
The big question is do you have Java outputing HTML or do you have HTML
trying to hook into code?
JSP's appear to provide some syntactic sugar as a solution, which
sounds nice but the limitations catch up very quickly.
Besides that to know how JSP's work you need to understand the Servlet
API anyway. Application scope, session scope, cookies, ... so it is not
a case of "one or the other".
Servlets can emit HTML and if you're wise you can do it in a tidy
fashion.
Most books and simple examples just do a crude out.print(...HTML
gut...) then go running to JSP for help but only to run from the frying
pan into the fire.
With Servlets you have the full power of a decent OO language at your
disposal, it is possible to do HTML simply and neatly with perhaps a
light dose of JSP.
The other path has led to progressive chaos!
First JSP
Then JSP + Taglibs
Then JSP + Taglibs + JSTL
Then JSP + Taglibs + JSTL + "EL" (Expression Language)
Then JSP + Taglibs + JSTL + "EL" + JSF (JavaServer Faces)
All because some people can't work out how to use OOP to output HTML
from Servlets in a reasonable OOP way.
JSF is to web pages what Swing is to GUI's so it's promising but that
is another topic.
HTH,
Cheers.