JAVA SERVER PAGES TECHNOLOGY
With the advent of internet, the monolithic application architecture changed to the multi-tiered client-server architecture. The need for server side scripting gradually began to dominate aspects of web programming. Microsoft introduced Active server a pages (ASP) to capture the market demand for server side scripting. Working on similar lines, Sun Microsystems released Java Server Pages ( JSP ) to add server side programming functionalities to java.
Introduction To JSP Technology
A typical web application consists of the presentation logic representing the static content used to design the structure of a web page in terms of the page layout, color, and text. The business logic or the dynamic content involves application of business calculations. When developing Web applications, time is often list in situations where the developer is required to code for the static content.
JSP Technology has facilitated the segregation of the work profile of the web designer and web developer. A web designer can design and formulate the layout for the web page by using HTML. On the other hand, a web developer working independently can use java code and other JSP specific tags to code the business logic. The simulations construction of the static and dynamic content facilities development of quality applications with increased productivity.
A JSP Page, after compilation, generates a servlet and therefore incorporates all servlet functionalities. Servlets and JSP thus share common features, such as platform independence, creation of database-driven web applications, and server side programming capabilities. However, there are also some basic differences between servlets and JSP.
- Servlets tie up files ( an HTML file for the static content and a java file for the dynamic content.) to independently handle the static presentation logic and the dynamic business logic. Due to this, a change made to any file requires recompilation of the servlet. JSP on the other hand allows java to be embedded directly into an HTML page by using special tags. The HML content and the java content can also be placed in separate files. Any changes made to HTML content is automatically compiled and loaded on to the server.
- Servlet programming involves extensive coding. Therefore, any change made to the code requires identification of the static code content( for the designer) and dynamic code content ( for the developer ) to facilitate incorporation of the changes. On the other hand, a JSP page, by virtue of the separate placement of the static and dynamic content, facilitates both web developers and the web designer to work independtly.
JSP Life Cycle
When the client browser requests for a particular JSP page, the server in turn sends a request JSP engine. A JSP engine is a part of web container that compiles a JSP page after a client requests for a JSP page.
Request-Response Cycle For a JSP Page
The request-response cycle comprises of two phases, namely the translation phase and the request-processing phase. The translation phase is implemented by the JSP engine and involves generation of a servlet. Internally, this results in the creation of a class file for the JSP page that implements the servlet interface. During the request-processing phase, the response is generated according to the request specifications. The servlet send back a response corresponding to the request received. After this servlet is loaded for the first time, it remains active, processes all the subsequent requests, and saves time that would otherwise be lost in reloading a servet at each request.
Once a JSP is translated to a servlet, the container invokes the following life cycle methods on the servlet that are dfined in the javax.servlet.jsp.JspPage interface.
This method is invoked at the time when the servlet is initialized.
This method is invoked when request for the JSP page is receved.
This method is invoked before the servlet is removed from the service.
Structure of a JSP Page
A JSP page consists of regular HTML tags representing the static content and the code enclosed with in special tags representing the dynamic content. These tags begin with”” symbol. The scripting and directive elements are written between “” symbols. The scripting elements consist of java code snippets, while directives used to define the specifications for the entire JSP page. Comment line entries that provide additional information about the various sections of the code are enclosed with in “” symbols. For example, the following JSP code displays the server time on the browser. It contains the HTML content and the JSP content placed separately within the respective tags.
Like it on Facebook, +1 on Google, Tweet it or share this article on other bookmarking websites.