JSP Syntax  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews JSP
Written by MS   
Wednesday, 25 April 2007

{mos_sb_discuss:34}

Introduction


JavaServer Pages (JSP) is a Java technology that allows software developers to dynamically generate HTML, XML or other types of documents in response to a Web client request. The technology allows Java code and certain pre-defined actions to be embedded into static content.It mixes regular, static HTML with dynamically-generated HTML.It mark servlet code with special tags.The entire JSP page gets translated into a servlet (once), and then servlet is what actually gets invoked (for each request).



Advantages of JSP

➢ Although JSP technically can't do anything servlets can't do, JSP makes it easier to write,read and maintain the HTML.
➢ JSP makes it possible to use standard HTML tools such as Macromedia DreamWeaver or Adobe GoLive.
➢ JSP encourages to separate the (Java) code that creates the content from the (HTML) code that presents it

JSP Syntax

A JavaServer Page may be broken down into the following pieces:
➢ Static data such as HTML,
➢ JSP directives such as the include directive,
➢ JSP scripting elements and variables,
➢ JSP actions
➢ Custom tags

Example

(Static HTML tag)



(JSP directives)

(JSP scripting elements)


(JSP actions)
name:<%=request.getParameter("extraparam")%>
(Custom tags)


JSP scripting elements and objects

JSP Implicit Objects

The following JSP implicit objects are exposed by the JSP container and can be referenced by the programmer:

➢ out – The JSPWriter used to write the data to the response stream.
➢ page – The servlet itself.
➢ pageContext – A PageContext instance that contains data associated with the whole page. A given HTML page may be passed among multiple JSPs.
➢ request – The HttpServletRequest object that provides HTTP request information.
➢ response – The HTTP response object.
➢ session – The HTTP session object that can be used to track information about a user from one request to another.
➢ config – Provides servlet configuration data.
➢ application – Data shared by all JSPs and servlets in the application.
➢ exception – Exceptions not caught by application code.

Scripting elements

There are three basic kinds of scripting elements that allow java code to be inserted directly into the servlet.

➢ A declaration tag places a variable definition inside the body of the java servlet class. Static data members may be defined as well.
<%! int serverInstanceVariable = 1; %>

➢ A scriptlet tag places the contained statements inside the _jspService() method of the java servlet class.
<% int localStackBasedVariable = 1;
out.println(localStackBasedVariable); %>

➢ An expression tag places an expression to be evaluated inside the java servlet class. Expressions should not be terminated with a semi-colon.
<%= "expanded inline data " + 1 %>

JSP actions

JSP actions are XML tags that invoke built-in web server functionality. The following actions are provided:

➢ jsp:include Similar to a subroutine, the Java servlet temporarily hands the request and response off to the specified JavaServer Page. Control will then return to the current JSP, once the other JSP has finished. Using this, JSP code will be shared between multiple other JSPs, rather than duplicated.
➢ jsp:param Can be used inside a jsp:include, jsp:forward or jsp:params block. Specifies a parameter that will be added to the request's current parameters.
➢ jsp:forward Used to hand off the request and response to another JSP or servlet. Control will never return to the current JSP.
➢ jsp:plugin Older versions of Netscape Navigator and Internet Explorer used different tags to embed an applet. This action generates the browser specific tag needed to include an applet.
➢ jsp:fallback The content to show if the browser does not support applets.
➢ jsp:getProperty Gets a property from the specified JavaBean.
➢ jsp:setProperty Sets a property in the specified JavaBean.
➢ jsp:useBean Creates or re-uses a JavaBean available to the JSP page.


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Tuesday, 05 June 2007 )
 
Next >