Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
Java Beans, tag libraries and JSPs - what and why.

Java Programming - training course! - just completed. We went a long way from the first steps in Java on Monday through to Servlets and Java Server Pages (JSPs) on Friday - and yet in many ways, our course goes full circle. For, through Java Server Pages, you can keep the look and feel of a web site separated from the business logic, and produce meaningful pages that contain - in the HTML - remarkablly little code if any. This excellent approach (sometimes known as MVC / Model, View, Controller) allows you to have your web page appearence looked after by those members of your team who are good graphic artists, and to have your actions looked after by other members of the team - the good analyst / programmers. You have a good interface between the two, you can change the way the thing works without the appearance, and the appearance without changing how it works. And you can have the page updated easily without having to employ a multi-skilled person - a graphic artist who's a programmer too (and who is, perhaps, only mediocre at one of those skills).

To show you what I mean ... from Friday, [here] is a link to a JSP page. You'll find that it has a grand total of two complete Java statements, and two other references to Java variables. The rest is all HTML.

A further example - [here] adds in a bit more code - but the complexity of doing the MySQL database lookup and presenting the results back has all been put into the net.wellho.Book class which is the responsibility of the programmer.

We can get rid of even that small amount of Java source code by providing the graphic artist with a tag library - in the third example in this series, [here], all the Java has gone to be replaced by tags which are very similar to HTML tags, but are replaced by results on the web server before being sent out to the site visitor's browser / client.

As well as the standard tag library, there are othe libraries available such as Spring and Struts. Those are beyond the scope of a course that takes you from "what is Java" in just a week - but at the end of the week it's good to be given the roadmap ahead and know where you may be headed.

• Above here - the graphic artist
• Below here - the programmer


The examples above apply a look and feel to a database lookup that needs to be codes. And the API (Application programmer interface) that the tag library uses is a Java Bean. What that means is that the program logic is going to be in a Java class, which must have a constructor that takes no parameters. Information (properties) are put in using methods with names like setIsbn where the word "set" is used to identify this as a method which supplies data to th eclass, and getAuthor where the word "get" identifies the method as one to extract data.

The net.wellho.Book class is such a bean - and that means that the tag libraries (which require that such a convention has been followed, thus turning it into a rule as far as they are concerned) can make use of it. You can find the source of the class [here] and you'll note that - like all good classes - it has its own main test harness so that you can check it out independently of the JSP / tag library / web level.
(written 2010-11-13)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
A508 - Web Application Deployment - Jakarta and Struts
J811 - Java - JDBC - Relational Database Access
  [2861] MySQL and Java - connectivity past, present, and future thoughts - (2010-07-09)
  [2154] Bean Classes in Java and Java Database Connections - (2009-05-02)
  [515] MySQL - an FAQ - (2005-12-03)

J812 - Java Beans
  [2155] No subject or title? - (2009-05-03)
  [1074] Java beans and classes, .war and .jar files - (2007-02-10)

J907 - JSP - JavaServer Pages
  [3997] Servlet v JSP (Java Server Page). What is the difference? - (2013-02-06)
  [2525] Using JSPs, Tag Libraries, Java Beans, Tomcat in one short example - (2009-12-04)
  [2183] Servlet life cycle, and Java Servlet variable scope - (2009-05-16)
  [2151] What is a JSP tag library? - (2009-05-01)
  [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
After Course Resources - do we publish sample answers. Example from Java Exceptions module.
Previous and next
or
Horse's mouth home
Forward to
What is a universal superclass? Java / Perl / Python / Other OO languages
Some other Articles
Views of Melksham - November 2010
Computer Graphics is fun - even if Java Applets are Old Hat
String handling - from first steps to practical examples
What is a universal superclass? Java / Perl / Python / Other OO languages
Java Beans, tag libraries and JSPs - what and why.
After Course Resources - do we publish sample answers. Example from Java Exceptions module.
Changing a Servlet - more that just editing and compiling
Gathering information - logging - with log4j. First steps.
Least Common Ancestor - what is it, and a Least Common Ancestor algorithm implemented in Perl
Java - basic rules for arithmetic, variables and conversion
4300 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 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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3046_Jav ... -why-.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat