Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Java Tag Libraries / how they work / Tomcat Deployment

A Java (JSP) tag library is a set of additional XML tags that you can include in your Java Server Page in order to create objects and set and get the attributes of those objects. Let's see an example.

I can write the following into my HTML:

<jsp:useBean id="bigmac" class="shape.Cube"/>
<jsp:setProperty name="bigmac" property="wid" value="150"/>
<jsp:setProperty name="bigmac" property="hig" value="140"/>
<jsp:setProperty name="bigmac" property="dep" value="100"/>
The Big Mac box has a volume of
<b><jsp:getProperty name="bigmac" property="vol"/> and

And that will result in an output like:

The Big Mac box has a volume of 2100 cc and

How does it work?

The extra tags in the library generate Java Byte Code (code for the Java Virtual Machine) even though there is no actual Java source code present ... but there is enough information to describe what the code needs to do - you can consider it to be another language if you like! Here's what the alternative source code would look like:

<% shape.Cube bigmac = new shape.Cube();
out.print(bigmac.getVol); %gt;

The whole of the JSP is read by the Tomcat (or other) JSP engine, and all the stuff that's NOT in the Java tags is put into a great big out.print() and the whole thing is compiled up into a Servlet, which Tomcat then runs.

Where does the calculation logic come from

The constructor for the shape.Cube object, and the accessor methods, conform to a standard called a Java Bean. This specifies that there must be a zero parameter constructor, and that there must be methods to save attributes / properties with names starting with set, and to read back properties with names starting with get. The business logic is within that class, or classes which it in turn calls.

The extra class file is stored within your web application, in teh directory WEB-INF/classes ... and in there in a subdirectory named to match the package name.

The extra class / business logic is loaded when the JSP is loaded.

Here's the start of the source code of the Java Bean to give you an idea of what it looks like:

package shape;
public class Cube {
   float x;
   float y;
   float z;
public Cube () {
   x = 0.0f;
   y = 0.0f;
   z = 0.0f;
public void setWid(String val) {
   x = Float.parseFloat(val);

Full source code of the JSP - [here]
Full source code of the Java Bean - [here]

Some Notes

Although the JSP page is rechecked by Tomcat every few seconds, the classes that it calls up are not - they're cached and assumed to be unchanging. So that means you'll need to stop and restart the application if you change the classes, but not if you change the JSP itself.

Note that the attribute names start with a lower case letter, but the method names are camel case with a capital for the attribute name. For example a property called dep will call up methods setDep and getDep.

You can learn about deploying applications that include pages that use tag libraries like this (N.B. - also other tage libraries such as Struts and Spring) on our Deploying Apache / Tomcat course. And we can teach you how to write pages like this on private Java courses - please email for a few more details, telling me a little of your background.
(written 2009-02-11)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J711 - Java in the Web Page
  [1325] Java - Client side applet applications as well as server side - (2007-08-29)
  [3049] Computer Graphics is fun - even if Java Applets are Old Hat - (2010-11-13)

J606 - Java Roadmap - Beyond the Fundamentals
  [1049] Java 6, Apache Tomcat 6. - (2007-01-21)
  [1562] Java Compiler - needs all classes, compiles them all too - (2008-03-03)
  [1910] Java - Generics - (2008-11-27)
  [3043] Gathering information - logging - with log4j. First steps. - (2010-11-12)
  [4305] Learning to program in Java - yes, we can help. - (2014-09-26)

Back to
1234567890 ... coming up on Friday 13th
Previous and next
Horse's mouth home
Forward to
The Interview and The Lift
Some other Articles
Error: Cant read xxxxx: no such variable (in Tcl Tk)
The Invoker
Sticky Sessions with mod_jk (httpd to Tomcat)
The Interview and The Lift
Java Tag Libraries / how they work / Tomcat Deployment
1234567890 ... coming up on Friday 13th
Through Snow and Flood to Linux and Tomcat
Huawei D100 Wireless Router - Mobile Internet
Mobile Internet - an alternative to hotel WiFi
Choosing from an image with an image map
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., 2023: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2036_Jav ... yment.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb