Thursday, November 27, 2008

Web Applications in My World - "JSP/J2EE/SERVLETS"














From the picture above you can see the overall architecture or models on which most web applications that are done in J2EE look like.

As you can see, a normal web app done in J2ee consists of jsp web pages, servlets if necessary, and data stores. Ideally all of these should be present, but it always depends on the type and complexity of the web app i do. In other words, a web app could contain all of these or just some, but not all.

The anatomy of the web application
In web applications developed using jsp and j2ee technologies (please refer to diagram) we see the following major highlights about the architecture of web applications.
1) Most users use the web browser as a client to the web enabled applications. This could be any browser from Mozilla Firefox, Internet Explorer, Safari, Opera, Netscape, or any other browser that can send and recieve HTTP and HTTPS requests and responses. Basically this means that even though you are on linux or windows or macintosh or solaris, any browser can access the webserver and get pages. In addition, (which has been ommited on the diagram) we could also have WAP enabled devices, those that can browse WAP applications based on WML, which is a form of Markup language for WAP devices like cellphones to allow clients to browse websites from their mobile devices like phones, pda's and so on.
2) The web server is a software program normally referred to in java terms as web container, because it contains and can handle, manage, process and server jsp pages and servlet classes.
3) The web server can also host java beans which are standard java classes that can access databases, file systems, and can do all that any ordinary java program can do, including networking via eSockets and XML processing.
4) The Enterprise tier consists of EJBs (Enterprise JAVA Beans), which are a specialized JAVA classes that are supposed to make connecting to databases as easy as drag and drop, and you don't need to write any sql queries or such thing. For more info, read books on EJBs coz i can't cover them all here.

Now the most interesting part of web applications is the webserver.
The browser sends an HTTP or HTTPS request to the webserver, from any location on the internet. WAP devices like mobile phones can also send WAP requests to the webserver.
Upon reciept of a request the webserver invokes the servlet class specified from the browser to handle the request. (Note that the request string contains information of which servlet to invoke). The servlet class, which is just a java class, is simply written by the programmer in simple JAVA code, and can do anything from accessing databases, instantiating other classes (inbuilt into the java runtime, or custom made by the programmer), access files in the local filesystem, XML files, network devices via sockets and so on, as well as either redirecting the request to another servlet class, jsp page, or returning a response back to the browser.
The servlet class takes the request string from the browser or WAP request, and the programmer extracts the various request parameters like form data, links, user agent, user infomation and so on. The programmer can then use this infromation to either process data, make calculations, or perhaps even query a database from the servlet class.
When done, the servlet either redirects the request to another servlet, or it renders HTML directly to a browser, or it can invoke a jsp page, which consists of java code mixed with HTML. Either way, a response is sent to the client (either browser or WAP device).
Besides just servicing HTTP requests, and WAP requests, servlets can also serve other protocols of the TCP/IP protocol stack.

More in the next post........

No comments:

Post a Comment