• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and Servlet  RSS feed

 
Suri Babs
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difference between Servlets and JSP?
Could any one make me clear about the difference.
thanks in advance.
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure there are many difference between the two. They are equal in function. Servlet is easy to read, jsp is more effcient.
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A fairly glib explanation is as follows:
Servlets are Java Classes that generate HTML (or other output)
JSPs are HTML-like files that generate Java Classes.

IMHO - JSP's are better for generating the 'View' tier of the architecture as they provide a better separation between the presentation and the business logic.
Servlets are usful for other purposes such as acting as the 'controller' for incoming requests i.e. delgating the processing and then forwarding the request to the next appropriate JSP or for handling requests for binary content such as documents or images.
Hope this helps
Andy Bowes
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the information!
 
Chris Smith
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One additional comment: the text vs. binary distinction, when deciding on servlets or JSPs for presentation, is not always right-on. There are lots of cases where you'll want to use a servlet to generate text, if it's not in a language in the style of XML, HTML, or WML.
JSPs tend to assume that you're using a format that involves tagged text with tags like <this>, and that your file format is immune to added whitespace, including newlines. If that's not the case, then although it is possible to use JSPs to produce the output, the result will look foreign and be difficult to maintain. In those cases, it's probably better to use a servlet to generate the content.
This can sometimes even become an issue for HTML <pre> tag sections, where whitespace and newlines become suddenly significant. Preformatted sections in HTML are often best written as JSP standard include actions that include the output of a servlet.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!