How a Glassfish Server Works

Normally I stick to posts on the more conceptual levels of programming, since I prefer to leave the technical details to the real experts, and I also find the psychological, cultural and historical side of software development pretty interesting too. However, I have been working with Java EE for a few months now and it has come to my attention that there is not very much out there for novice programmers about what is going on under the hood in a Java EE compliant server. So here is a short introduction for novices who want to get an idea of what is actually going on when they run their webapp. Incidentally, I begin this discussion from the perspective of Java EE7, running on Glassfish 4.1 and JavaServerFaces 2.2.

This discussion will not go into a lot of detail about how to program a Java Web Application. As noted above, I leave that to the experts, but if that is what you are looking for then BalusC provides an excellent set of tutorials.

What is a JavaServerFaces(JSF) Page?

What exactly is a JSF page? Well, be clear about one thing: it is not an html page, at least not in the sense that most people think of html. An html page is created using a JSF page by a Java EE compliant server. If you were to simply put a JSF page directly into a browser you would not get what you expected - you would, in fact get a largely blank page, since none of the tags in JSF actually mean anything to a browser; they would view them as an error and ignore them.

Take, for example the following standard JSF tag:

 <h:outputLabel value="tutorial" />  

OutputLabel is a standard JSF tag that represents an html label. If you view the source of a page that such a tag is displayed on in a browser you would see something like this:

 <label id="j_idt6" class="ui-outputlabel ui-widget">Tutorial</label>  

What has happened is that the server has read the outputLabel, and its title attribute, and then converted that into an html label tag with an automatically generated id and an automatically generated CSS class value.

An outputLabel is a Component. A Component actually has several parts to it. It has the tag, and it also has a Java class associated with it that tells the server what to do with it. It can also have its own css files and javascript, but I won't be going into those for now.

So, when you write a page in JSF you are not writing anything for the browser to interpret, you are writing code for the server to interpret. The server converts the tags using the information provided to it by you in the JSF page, and the instructions it has received for how that data should be displayed as html for the browser.

So that's the basic idea. You write the page in JSF, and the server converts it into html. There is, however quite a lot more to it than that, specifically (and very importantly) the Request Processing Lifecycle.

Comments

Popular Posts