A First implementation on Glassfish
I've dug out this project from the archives in order to write this post, and also as an entry to a contest.
Anyways, I'll begin with a little context. I know a bit of web designing, and I use PHP primarily. That was, until a project came along, as part of my curriculum, that required me to use Java for a website. The project was to make a website for fests, that is competitions, technical or otherwise. Of course, shifting to a new language can be easy if the paradigm is the same, but if you really want to take advantage, you have to take into account the strengths of the language.
Web design can be divided into two parts primarily, the user-interface, and the backend, all the business logic, and functionality of your project. PHP uses a method where your code, and your UI, that is the HTML part, come in together. Moreover, it does not use object-oriented programming all that much. While, there is something to be said about the advantages of the same, this kind of design makes it rather difficult to seperate these tasks into two. JSP uses a different approach for this, and that is where the primary difference lies.
JSP is based on a simple concept, bring Java coding to the web. The same language and library that has made the Java programming language such a success has made available on the web. Of course, it does not include the entire thing. As a matter of fact, while the Java library is J2SE, the Web Development part is called J2EE. What makes it possible is a J2EE container, basically a web server that can be used to execute J2EE code. This includes Tomcat, and it's more elaborate, and modern-day alternative Glassfish. While JSP pages are analogous to PHP, Servlets are also a part of this package, and they are kind of a Java class that returns HTML code. Unfortunately, that's not a very elegant solution, and hence I found Servlets to be inappropriate. However, servlets can serve as controllers, that is, they can manage where a control goes from one page to another, so that you do not have to put that part in the JSP page.
Next come the various web frameworks available, like spring and Struts. They are based on an MVC framework, which you can find out more about on the wikipedia page. Such a framework can prove very useful for seperating the various layers of the project, ie. the business logic layer, application layer, and data layer. They provide some good facilities, though those were not the end aim of the project, so I decided to skip an MVC framework, or servlets. Now, another concept that differs from PHP is the use of tag libraries.
Now, a JSP page, much like a PHP page will contain both code, and HTML. In order to eliminate that, the tag library concept was invented. It is essentially a set of HTML like notation that can be used to implement code like functionality, without neccessarily coding. This helps to make the task of the webpage designer just to use tags, and not code. Of course, tag libraries are extendable too. There as also, JavaBeans and Enterprise JavaBeans (EJBs) which are standard ways to code classes so that it makes the task of coding for webpages easier. I wouldn't really go into the details of how.
Thus, designing a web application is very different for J2EE as compared to PHP. It does tend to break up work into many different parts, which augurs well for larger organizations. As I said, Glassfish is what makes it all possible. It is the reference implementation for the J2EE platform, which means that if you want to know how the J2EE standards should be implemented, this is where you need to look. It also uses Grizzly as the HTTP frontend, which is written in Java, and is thus integrated right into the application server. Finally the addition of clustering, the Metro stack for web services, and a JPA implementation ensure that there's plenty to look forward to with Glassfish, on top of Tomcat.
Of course, what has enabled the wide-spread popularity of PHP is the entire LAMP, WAMP or SAMP stack, that it is a part of. That refers to Linux, Apache, MySQL, PHP (or Python or Perl). This is the combination of an operating system, a web server, a database server, and the lanugage, which is actually the more readily substitutable part of the stack. MySQL, of course is the leading open-source database server, and amongst the most widely used ones worldwide. It supports a wide variety of techniques and is available on a large number of platforms. SQL, stored procedures, triggers, cursor
s, etc. are obviously supported. It also supports clustering using the shared-nothing scheme. Of course, the fact that is allows for different storage engines adds merit.
Thus, for my project, I used Glassfish, MySQL and also Netbeans, which helped to bring it all together. I used a simple scheme that utilized JavaBeans, and coded all the functionality in Java classes. However, I did not use Servlets, or an MVC framework. The JSP classes contained only minor pieces of code such as for loops and stuff. However, the way such efforts can benefit should be obvious from the unit tests that could be easily defined for the Java classes. All in all, a good learning experience.
Posted at 12:34AM Oct 23, 2008 by Aadhar Mittal in Sun | Comments[1]
Congratulations. Keep up the spirit.
Posted by Naveen Kumar on November 27, 2008 at 01:46 PM IST #