Wednesday, July 23, 2014

JSP:The Basic Syntax

There are different jsp tags or elements. All tags are case sensitive. The elements in a JSP page can be expressed in JSP syntax or XML syntax.
There are following rules that are followed while developing JSP page.
1. JSP and XML syntax cannot be mixed within a page.
2. A page in one syntax can include or forward to a page in the other syntax.
3. Some elements have attributes whose value can be computed at request time. In JSP syntax, the format of a value is the same as a JSP expression: <%= expression%>. In XML syntax, the format of the value is %= expression %.
The common tags or elements we use in JSP are as follows
1.jsp:root: Defines standard elements and namespace attributes of tag libraries.
2.Hidden Comment: Documents the JSP page but is not inserted into the response.
3.Declaration: Declares a variable or method valid in the scripting language used in the page.
4.Expression: Contains an expression valid in the scripting language used in the page.
5.Scriptlet: Contains a code fragment valid in the scripting language used in the page.
6jsp:text: Encloses template data.
7.Include Directive: Includes a resource of text or code when the JSP page is translated.
8.Page Directive: Defines attributes that apply to an entire JSP page.
9.Taglib Directive: Defines a tag library and prefix for the custom tags used in the JSP page.
10.jsp:forward: Forwards a request to an HTML file, JSP page, or servlet.
11.jsp:getProperty: Inserts the value of a bean property into the response.
12.jsp:include: Includes a static resource or the result from another web component
13.jsp:plugin: Causes the execution of an applet or bean. The applet or bean executes in the
specified plugin.If the plugin is not available, the client displays a dialog to initiate the download
of the plugin software.
14.jsp:setProperty: Sets a bean property value or values.
15.jsp:useBean: Instantiates or references a bean with a specific name and scope..
 
 

Tuesday, July 22, 2014

JSP:The Lifecycle

A JSP page services requests as a servlet. So, the life cycle of JSP are determined by Java Servlet technology.
There are following steps followed by JSP
1.Translation and Compilation
2.Initialization
3.Execution
4.Destruction
Translation and Compilation
When a browser asks for a JSP, the web container first checks to see whether the JSP page's servlet is older than the JSP page. If the servlet is older, the web container translates the JSP page into a servlet class and compiles the class. During development, one of the advantages of JSP pages over servlets is that the build process is performed automatically.During the translation phase each type of data (Html and JSP elements) in a JSP page is treated differently. Both the translation and the compilation phases can yield errors that are observed only when the page is requested for the first time. If an error is encountered during either phase, the servers will return JasperException and a message that includes the name of the JSP page and the line where the error occurred.
Initialization
After the page has been translated and compiled, container loads JSP page’s servlet class and instantiates an instance of the servlet class by calling jspInit method.
Execution
Whenever a browser requests a JSP and the page has been loaded and initialized, the web container invokes the _jspService () method in the JSP.
The _jspService () method takes an HttpServletRequest and an HttpServletResponse as its parameter. The _jspService () method of a JSP is invoked once per a request and is responsible for generating the response for that request. We can control various JSP page execution parameters by using page directive. When a JSP page is executed, output written to the response object is automatically buffered. We can set the size of the buffer using the following page directive:
<%@ page buffer="none|xxxkb" %>
A larger buffer allows more content to be written before anything is actually sent back to the client, thus providing the JSP page with more time to set appropriate status codes and headers or to forward to another web resource. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.
Destruction
The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container. If the container needs to remove the JSP page's servlet, it calls the jspDestroy method.

JSP:An Architecture

JSP Architecture
Web browser directly accesses the JSP page of web container. The JSP pages interact with the web container’s JavaBeans which represent the application model. When client sends request from a JSP page, the response is sent back to the client depending on the requests which are invoked by the client request. If response requires accessing the database, the JSP page uses JavaBeans to get data from the database.

Monday, July 21, 2014

JSP:A Overview

JavaServer Pages(TM) is a technology specified by Sun Microsystems as a convenient way of generating dynamic content in pages that are output by a Web application (an application running on a Web server). JSP enables us to separate the dynamic content of webpage from static presentation content. A JSP page consists of HTML tags and JSP tags. HTML tags are used to create static page content and JSP tags are used to add dynamic content to web pages.
Why JSP?
Some benefits are following:
1.Web pages created using JSP are portable and can be used across multiple platforms without making any changes.
2.JSP pages are automatically compiled by servers. Developers need to compile JSP pages when the source code of the JSP page is changed.
3.Most important benefit of JSP is the separation of business logic from presentation logic. JavaBeans contain business logic and JSP pages contain presentation logic. This separation makes an application created in JSP more secure and reusable.
4.It easily combines static templates like HTML or XML fragments.
5.Its environment provides compilation of pages automatically.
6.Servlets cannot be accessed directly whereas a JSP page can be accessed directly as a simple HTML page.


Copyright © Codingnodes,2014.All Rights Reserved.