An Introduction To JSP

An Introduction To JSP


Posted in : Java Posted on : January 23, 2012 at 6:20 PM Comments : [ 0 ]

When we are going to study about JSP, it is important to know that what is the use of JSP obviously, it is for creating a Web content that contains both static and dynamic components.

An Introduction To JSP

When we are going to study about JSP, it is important to know that what is the use of JSP obviously, it is for creating a Web content that contains both static and dynamic components. For creating a dynamic content it uses the potentials of Java servlet technology and for a static content it uses a natural way. So a JSP is textual document. It contains two types of text :- static and dynamic. Static text can be HTML, SVG, WML, and XML. Dynamic contents are made by JSP elements, JSP elements are translated and executed by the JSP Server.

JSP Elements are as follows :

Directive Element :

Directive elements keeps the page info of itself that persist the similar between requests for the page. It provides us to handle the main structure of the servlet.

Syntax :

<%@ directiveName attributeList %>

Here the directiveName can be either of the three values page, include, and taglib.

And attributeList is name-value pairs. (atrributeList = attr1= "value1" attr2 = "value2")

The directiveName and attribute names are case sensitive and the attribute values should be closed in double quotes.

Action Element :

Actions in JSP performs the action depending upon the request done by a browser for the required information. These action tags controls the transformation between pages. 

Syntax :

<jsp:action attributes />

There are various actions in JSP but the three mostly used actions are :

include

forward

useBean

Scripting Element :

A Scripting element facilitate you to embed the java code into the servlet. A JSP page can have the following scripting element :

* Scriptlet Element : A JSP Scriptlet holds a reasonable code fragment of a scripting language used in a page. Java Statement that are written inside the scriptlet are inserted into the servlet's service method.

Syntax :

<%  code  %>

* Expression Element : In JSP Expressions the value of a scripting language expressions are inserted. In Java scripting language JSP expression inserts java values directly into the output.

Syntax :

<%=  expression  %>

* Declaration Element : A JSP Declaration facilitate to declares methods or fields into a JSP page. Methods or fields that are declared into a jsp page inside the declaration are put inside the body of servlet class.

Syntax :

<%!  code  %>

Example : Here we are giving a simple jsp example

JspPage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD></HEAD>
<TITLE>Jsp Demo</TITLE>
<BODY>
<h3>This is a simple JSP Page Example.</h3><br>
The current Date is : <%= new java.util.Date() %>
</BODY>
</HTML>

Output

When you will execute the above example you will get the output as :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics