In this article we are going to explore the information about Java Servlets in detail. In previous Part-II article of web application technologies, we had taken overview of java server technologies.

Java Servlets:

  • Servlets run within the Java EE component container architecture. This container is called as the web container (also known as the servlet engine).
  • The web container is a Java virtual machine (JVM) tool interface that supplies an implementation of the servlet API.
  • Servlet instances are components that are managed by the web container to respond to HTTP requests.

 

Introduction to Web Application Technologies : Part-3

 

Note: In some architectures, the web container acts as a standalone HTTP service. In other architectures, the HTTP service forwards requests to be processed by the web container.

Java Server Pages Technology:

  • All template page technologies have the same fundamental structure: an HTML page that a web designer can easily create, with special tags that indicate to the web server that code needs to be executed at request time.
  • In this we are only going to focus on JSP pages.
  • JSP pages are the opposite of servlets. Instead of Java technology code that contains HTML, template pages are HTML that contains into a servlet instance. That servlet then does process each request to that JSP page.
  • The JSP page runs as a servlet. Everything that you can do in a servlet you can do in a JSP page. The main difference is that a JSP page should focus on the presentation logic of the web application.

Note: JSP pages are just one way of implementing the concept of HTML pages embedded code, or template pages. These examples of other popular technologies available for creating HTML with embedded code are PHP Hypertext Preprocessor (PHP), Active Server Pages (ASP), and Ruby on Rails.

  • With JSP pages, Java technology code fragments are embedded in an HTML like file. This code is executed at runtime to create dynamic content.
  • The example given below shows JSP template page.

 

  1. <html>
  2. <head>
  3. <title>Example JSP Page</title>
  4. </head>
  5. <body bgcolor = ‘white’>
  6. <b>Tables of numbers squared:</b>
  7. <table border = ‘1’ cellspacing = ‘0’ cellpadding = ‘5’>
  8. <tr><th>number</th><th>squared</th></tr>
  9. <% for(int i = 0; i<10; i++) {%>
  10. <tr><td><% = i %></td><td><% = (i * i) %></td></tr>
  11. <% } %>
  12. </table>
  13. </body>
  14. </html>

 

  • This example page generates an HTML table with the numbers 0 through 9 in the first column, and the corresponding squares in the second column.
  • The figure given below shows a screen shot from the generated page.

 

Number Squared
0 0
1 1
2 4
3 9
4 16
5 25
6 36
7 49
8 64
9 81

 

Concerns When Using Servlets and JSP Technology:

Because JSP pages are translated into Java servlets, JSP technology has all of the following advantages of servlets:

  • Web applications using JSP pages have high performance and scalability because they use threads rather than the OS’s shells or processes.
  • JSP technology is built on Java technology, so it is platform independent.
  • JSP scripting elements can be written in the Java language so that JSP pages can take advantage of the object oriented language and its API’s.

JSP technology has the following disadvantages:

  • If JSP pages are used in isolation, then the scripting code that does perform business and control logic can become cumbersome in the JSP pages. The JSP pages are also difficult to debug.
  • There is separation of a concerns into a business logic and presentation logic.
  • There are concurrency issues.

A properly designed web application should use servlets and JSP pages together to achieve separation of concerns. JSP pages provide technologies to help in this, namely custom tags and JSP Extension Language.

Web Application – Three Tier Architecture:

  • The three tier architecture (also referred to as a model or pattern) has a user interface client that runs on a user’s machine that communicates with business logic software on a server machine, which in turn communicates with software responsible for the long term storage of data on database machines.
  • By acknowledging the three tiers, web application development can be conceptualized as modules with simple, well defined interfaces.
  • The user interface clients resides in presentation (or client)tier. The business logic software resides in the middle ware (or business logic) tier. And the long term data storage is called the persistence (or data) tier.
  • These tiers are concepts and not rigid implementations; each tier may include several server machines hosting various aspects of that tier’s functionality.
  • Sometimes the three tiered architecture is referred as a multi-tier or n tier architecture.
  • In a two tiered architecture the client communicates directly with the data tier. A three tier architecture separates the components of a two tier architecture by adding a business logic tier between the data and client tier.
  • The problem with two tiered architecture is the client and the data are inflexibly bound to each other. If the data structure changes, the two tier architecture might not work until the client tier is updated to reflect the changes.
  • When the client must be updated on many user systems, the process of changing (or fixing) an application can be quite vexing.
  • By introducing a middle ware layer, changes in the data layer can be masked by updating the middle ware to account for the changes.
  • Also, and more importantly, new applications can be created by applying new business logic to existing data structures.
  • Because the data is so important to modern business operation, changes to the data layer should never be taken lightly.
  • If the user interface client is based on communicating using common standards, for example a web browser based on HTTP and HTML, then no changes to the clients are needed, and new applications can be built solely by focusing on the middle ware tier.
  • As a result of these efficiencies, three tier architecture has been a great boon of the operation of modern business.

Written by Sourabh Bhunje

Sourabh Bhunje, B.E. IT from Pune University. Currently Working at Techliebe. Professional Skills: Programming - Software & Mobile, Web & Graphic Design, Localization, Content Writing, Sub-Titling etc. http://techliebe.com/about-us

Leave a Comment