Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Servlet v JSP (Java Server Page). What is the difference?

A servlet is a web program that generates output (normally HTML) and returns it to a browser.

A JSP (Java Server Page) is a page of HTML ... with some extra bits of code where programatic elements are added as it's returned to the browser

So on the surface, it looks like there's a fundamental difference. Internally, however, Tomcat converts your .jsp pages into servlets, by taking all the elements which are outside the extra bits and putting them into out.print statements in Java source, which is then compiled. So - in reallity - a .jsp is a servlet in disguise.

You can see this in action if you wish. Tomcat's work directory is used for the conversion to Java source, and the compiling into class files, of your servlets, and (by default) the source code is left there for you to look at if you wish. Here's an example of where to look - default configuration, application called "wetfeet", host "locathost", file called "together.jsp" ...
/usr/local/tomcat/work/Catalina/localhost/wetfeet/org/apache/jsp/together_jsp.java

Taking some examples, a line like
  Here is the <%= number %> times table
converts to
  out.write("Here is the ");
  out.print( number );
  out.write(" times table \n");


and
  <% for (int k=1; k<=maxtimes; k++) {
  int result = k * number; %>
  <tr><td><%= k %></td><td><%= result %></td></tr>
  <% } %>

converts to
  for (int k=1; k<=maxtimes; k++) {
  int result = k * number;
  out.write("\n");
  out.write("<tr><td>");
  out.print( k );
  out.write("</td><td>");
  out.print( result );
  out.write("</td></tr>\n");
  }


Complete example - .jsp source [here] and the generated servlet source [here].

Example from today's private Apache htpd and Tomcat course, which has been tailored for this customer from our public httpd and Tomcat class.
(written 2013-02-06, updated 2013-02-07)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A507 - Web Application Deployment - Java - Servlets and JSPs
  [4431] A Java servlet that is also a stand alone program. And a server that is also a web client. - (2015-02-19)
  [3044] Changing a Servlet - more that just editing and compiling - (2010-11-12)
  [2525] Using JSPs, Tag Libraries, Java Beans, Tomcat in one short example - (2009-12-04)
  [2151] What is a JSP tag library? - (2009-05-01)
  [479] New servlet from old - (2005-10-28)

A651 - Web Application Deployment - Tomcat Overview
  [4434] Public training courses - upcoming dates - (2015-02-21)
  [2753] You do not just fly - that is just part of the journey - (2010-05-06)
  [2186] An FAQ on the Apache httpd and Apache Tomcat web servers, and on using them together - (2009-05-17)
  [2077] Why put Apache httpd in front of Apache Tomcat - (2009-03-12)
  [2016] Apache httpd and Apache Tomcat miscellany - (2009-01-30)
  [1941] Server - Service - Engine - Host, Tomcat - (2008-12-14)
  [1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
  [1265] Apache, Tomcat, Jakarta, httpd, web server - what are they? - (2007-07-13)
  [659] Web Application Components - (2006-03-28)
  [576] Why run two different web servers - (2006-01-25)
  [498] Why is Tomcat called Tomcat? - (2005-11-17)
  [49] Business is the predominant user of Tomcat, Perl and Tcl - (2004-09-15)

J901 - Java - Servlets
  [4432] Java web application for teaching - now with sessions and clustering / load balancing demonstrations - (2015-02-20)
  [2652] Reading and writing cookies in Java Servlets and JSPs - (2010-02-26)
  [1909] javax.servlet cannot be resolved - how to solve - (2008-11-26)

J907 - JSP - JavaServer Pages
  [3046] Java Beans, tag libraries and JSPs - what and why. - (2010-11-13)
  [2183] Servlet life cycle, and Java Servlet variable scope - (2009-05-16)
  [2147] A very easy JSP (Java Server Page) - (2009-05-01)
  [1550] Java (JSP and Servlet examples) live on our server - (2008-02-23)
  [1050] The HTML++ Metalanguage - (2007-01-22)
  [79] Last day of Java - (2004-10-08)


Back to
Tips on Tomcat - moving applications around
Previous and next
or
Horse's mouth home
Forward to
Travelogue - from the Netherlands to London via Hook and Harwich
Some other Articles
Helping search engines with appropriate 400 error codes
9 years, and 4000 articles on
Handling failures / absences of your backend server nicely
Travelogue - from the Netherlands to London via Hook and Harwich
Servlet v JSP (Java Server Page). What is the difference?
Tips on Tomcat - moving applications around
Onward from Brussels
On board Eurostar - a running commentary
Two trains a day ... how many fares to London? Guess!
Conference and Meeting Rooms available in Melksham
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3997_Ser ... ence-.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat