java4all@1986 java. Powered by Blogger.

Life Cycle of Jsp?

>> Tuesday, June 14, 2011

                                                                       LifeCycle
                   
                                      
     A JSP page is executed in a JSP container or a JSP engine, which is installed in a web server or in a application server. When a client asks for a JSP page the engine wraps up the request and delivers it to the JSP page along with a response object. The JSP page processes the request and modifies the response object to incorporate the communication with the client. The container or the engine, on getting the response, wraps up the responses from the JSP page and delivers it to the client. The underlying layer for a JSP is actually a servlet implementation. The abstractions of the request and response are the same as the ServletRequest and ServletResponse respectively. If the protocol used is HTTP, then the corresponding objects are HttpServletRequest and HttpServletResponse.

The first time the engine intercepts a request for a JSP, it compiles this translation unit (the JSP page and other dependent files) into a class file that implements the servlet protocol. If the dependent files are other JSPs they are compiled into their own classes. The servlet class generated at the end of the translation process must extend a superclass that is either

1. specified by the JSP author through the use of the extends attribute in the page directive or

2. is a JSP container specific implementation class that implements javax.servlet.jsp.JspPage interface and provides some basic page specific behavior.

Since most JSP pages use HTTP, their implementation classes must actually implement the javax.servlet.jsp.HttpJspPage interface, which is a sub interface of javax.servlet.jsp.JspPage.

The javax.servlet.jsp.JspPage interface contains two methods:

1. public void jspInit() - This method is invoked when the JSP is initialized and the page authors are free to provide initialization of the JSP by implementing this method in their JSPs.

2. public void jspDestroy() - This method is invoked when the JSP is about to be destroyed by the container. Similar to above, page authors can provide their own implementation.

The javax.servlet.jsp.HttpJspPage interface contains one method:

public void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

This method generated by the JSP container is invoked, every time a request comes to the JSP. The request is processed and the JSP generates appropriate response. This response is taken by the container and passed back to the client.               

Read more...

What are the compnents of Jsp?

                                                    COMPONENTS OF JSP :

JSP syntax is almost similar to XML syntax. The following general rules are applicable to all JSP tags.

1. Tags have either a start tag with optional attributes, an optional body, and a matching end tag or
they have an empty tag possibly with attributes.

2. Attribute values in the tag always appear quoted. The special strings ' and " can be used if quotes
are a part of the attribute value itself.

Any whitespace within the body text of a document is not significant, but is preserved, which means that any
whitespace in the JSP being translated is read and preserved during translation into a servlet.

The character \ can be used as an escape character in a tag, for instance, to use the % character, \% can be used.

JavaServer Pages are text files that combine standard HTML and new scripting tags. JSPs look like HTML,
but they get compiled into Java servlets the first time they are invoked. The resulting servlet is a combination of HTML from the JSP file and embedded dynamic content specified by the new tags. Everything in a JSP page can be divided into two categories:

1. Elements that are processed on the server

2. Template data or everything other than elements, that the engine processing the JSP engines.

Element data or that part of the JSP which is processed on the server, can be classified into the following categories:

1. Directives

2. Scripting elements

3. Standard actions

                                                   1.JSP directives serve as messages to the JSP container from the JSP. They are used to set global values such as class declaration,methods to be implemented, output content type, etc. They do not produce any output to the client. All directives have scope of the entire JSP file. That is, a directive affects the whole JSP file, and only that JSP file. Directives are characterized by the @ characterwithin the tag and the general syntax is:
The three directives are page, include and taglib.

                                                                           2.Scripting elements are used to include scripting code (Java code) within the JSP. They allow to declare variables and methods,include arbitrary scripting code and evaluate an expression. The three types of scripting element are: Declaration, Scriptlets and Expressions.

A declaration is a block of Java code in a JSP that is used to define class-wide variables and methods in the generated class file.Declarations are initialized when the JSP page is initialized and have class scope. Anything defined in a declaration is available throughout the JSP,to other declarations, expressions or code.

                                              A scriptlet consists of one or more valid Java statements.
A scriptlet is a block of Java code that is executed at request-processing time.
A scriptlet is enclosed between "<%" and "%>". What the scriptlet actually does depends on the code,
and it can produce output into the output stream to the client. Multiple scriptlets are combined in the
compiled class in the order in which they appear in the JSP. Scriptlets like any other Java code block or method,can modify objects inside them as a result of method invocations.

An expression is a shorthand notation for a scriptlet that outputs a value in the response stream back to the client. When the expression is evaluated, the result is converted to a string and displayed, An expression is enclosed within <%= and %> "<%=" and "%>". If any part of expression is an object, the conversion is done using the toString() method of the object.

                                                                     3.Standard actions are specific tags that affect the runtime behavior of the JSP and affect the response sent back to the client. The JSP specification lists some standard action types to be provided by all containers, irrespective of the implementation.Standard actions provide page authors with some basic functionality to exploit; the vendor is free to provide other actions to enhance behavior.

Read more...

An overview of Jsp?

                                        JSP FLOW  and OVERVIEW:

       The JavaServer Pages 1.2 specification provides web developers with a framework to build applications containing dynamic web content
such as HTML, DHTML, XHTML and XML. A JSP page is a text based document containing static HTML and dynamic actions which describe how
to process a response to the client in a more powerful and flexible manner. Most of a JSP file is plain HTML but it also has,
interspersed with it, special JSP tags.

There are many JSP tags such as:

    1.JSP directive denoted by <%@,

    2. scriplets indicated by <% ... %> tags and directive includes the contents of the file sample.html in the response at that point.

To process a JSP file, we need a JSP engine that can be connected with a web server or can be accommodated inside a web server.

Firstly when a web browser seeks a JSP file through an URL from the web server, the web server recognizes the .jsp file extension in the
URL requested by the browser and understands that the requested resource is a JavaServer Page. Then the web server passes the request to the JSP engine.
The JSP page is then translated into a Java class, which is then compiled into a servlet.
This translation and compilation phase occurs only when the JSP file is requested for the first time, or if it undergoes any changes to the extent
of getting retranslated and recompiled. For each additional request of the JSP page thereafter, the request directly goes to the servlet byte code,
which is already in memory. Thus when a request comes for a servlet, an init() method is called when the Servlet is first loaded into the virtual machine,
to perform any global initialization that every request of the servlet will need. Then the individual requests are sent to a service() method, where the response
is put together. The servlet creates a new thread to run service() method for each request. The request from the browser is converted into a Java object of type HttpServletRequest,
which is passed to the Servlet along with an HttpServletResponse object that is used to send the response back to the browser. The servlet code performs the operations specified by
the JSP elements in the .jsp file.

Read more...

Installing and Developing Jsp First Application?

                                                               INSTALLING JSP:
 

First of all download JavaServer Web Development Kit (JSWDK1.0.1) from http://java.sun.com/products/servlet/download.html.
JSWDK comes with full documentation and it's very easy to install, so the installation process is not mentioned here.
The JSWDK is the official reference implementation of the servlet 2.1 and JSP 1.0 specifications.
It is used as a small stand-alone server for testing servlets and JSP pages before they are deployed to a full Web server that supports these technologies.
It is free and reliable, but takes quite a bit of effort to install and configure.

Other Servers that support JSP

    Apache Tomcat.
    Tomcat is the official reference implementation of the servlet 2.2 and JSP 1.1 specifications. It can be used as a small stand-alone server for testing servlets and JSP pages, or can be integrated into the Apache Web server.

    Allaire JRun.
    JRun is a servlet and JSP engine that can be plugged into Netscape Enterprise or FastTrack servers, IIS, Microsoft Personal Web Server, older versions of Apache, O?Reilly?s WebSite, or StarNine WebSTAR.

    New Atlanta?s ServletExec.
    ServletExec is a fast servlet and JSP engine that can be plugged into most popular Web servers for Solaris, Windows, MacOS, HP-UX and Linux. You can download and use it for free, but many of the advanced features and administration utilities are disabled until you purchase a license.

    Gefion's LiteWebServer (LWS). LWS is a small free Web server that supports servlets version 2.2 and JSP 1.1.
    GNU JSP. free, open source engine that can be installed on apache web server.

    PolyJSP. PolyJsp is based on XML/XSL and has been designed to be extensible. Now supports WebL
 
    JRUN. Available for IIS server.

 WEBSPHERE:IBM's WebSphere very large application server now implements JSP.
                                                   
                                                         DEVELOPING JSP APPLICATION
Jsp's should be save with .jsp extension.
<html>
<head>
<title>First JSP page.</title>
</head>
<body>
<p align="center"><font color="#FF0000" size="6"><%="Java Developers Paradise"%></font></p>
<p align="center"><font color="#800000" size="6"><%="Hello JSP"%> </font></p>
</body>
</html>


Read more...

What is meant by Jsp?

Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites.
JSP provide excellent server side scripting support for creating database driven web applications.
JSP enable the developers to directly insert java code into jsp file,
this makes the development process very simple and its maintenance also becomes very easy.  JSP pages are efficient,it loads into the web servers memory  on receiving the request very first time and the subsequent calls are served within a very short period of time.



In today's environment most web sites servers dynamic pages based on user request.
Database is very convenient way to store the data of users and other things.
JDBC provide excellent database connectivity in heterogeneous database environment.
Using JSP and JDBC its very easy to develop database driven web application.
Java is known for its characteristic of "write once, run anywhere." JSP pages are platform independent.
Your port your .Jsp pages to any platform.

Read more...

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP