Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: JSP FUNDAMENTALS

JSP FUNDAMENTALS JSP FUNDAMENTALS By: Hrishikesh Deshpande Introduction : JSP termed as Java Server Pages is a technology introduced by Sun Microsystems Inc. to develop the web application in more efficient way than Servlets. It has got many

Tutorial Details:

advanced features than servlets, one of them itself define the JSP i.e. JSP separates the presentation logic from the business logic and provide the designer and developer of the web application to work independently without any hassle.
Lets start with the basic of the JSPs, JSP is flavour of Cold fusion and ASP and hence provide the flexibility to embed the business logic efficiently within the HTML content (presentation logic).
JSP page is built using components such as :
Directives
Declarations
Scriplets
Expressions
Standard Actions
Custom Tags
Directives :
Listing some of them to start off :
1) Page
Syntax : < %@ page Language=”Java” extends=”” import=” or ” %>
Attributes:
a. Language = “Java”
b. Import = “Class”
c. Buffersize = “”
d. Scope = “REQUEST/PAGE/SESSION/APPLICATION”
e. And etc….
Page directive is aimed to define certain attribute of a JSP page for e.g. Language of the page in which the page content should be written , which class to be imported so that it can be used within the JSP page.
2) Include
Syntax: <%@ include file=”” %>
Attributes:
a. file = “
This directive is to include the a HTML, JSP or Sevlet file into a JSP file. This is a static inclusion of file i.e. it will be included into the JSP file at the time of compilation and once the JSP file is compiled any changes in the included the file will not the reflected.
Declarations:
Syntax: <%! Declare all the variables here %>
Scriplets:
Syntax: <% All your scripts will come here %>
Expressions:
Syntax: <%= expression evaluation and display the variable %>
Standard Action:
Syntax:
Include ” />
This inclusion of file is dynamic and the specified file is included in the JSP file at run-time i.e. out put of the included file is inserted into the JSP file.
Forward ” />
This will redirect to the different page without notifying browser.
And many more.
Custom Tags:
taglib
Syntax: <%@ taglib uri=”” prefix=”” %>
Attributes:
a. uri = “
b. prefix = “
prefix is alias name for the tag library name.
JSP provides certain Implicit Objects listed below.
Object
Of Kind
Out
JSP writer
Request
HttpServletRequest
Response
HttpServletRespose
Session
HttpSession
Application
ServletContext
Config
Sevlet Config
Page
Object
PageContext
Page Context => is responsible for generating all other implicit objects.
Out:
This object is instantiated implicitly from JSP Writer class and can be used for displaying anything within delimiters.
For e.g. out.println(“Hi Buddy”);
Request:
It is also an implicit object of class HttpServletRequest class and using this object request parameters can be accessed.
For e.g. in case of retrieval of parameters from last form is as follows:
request.getParameters(“Name”);
Where “Name” is the form element.
Response:
It is also an implicit object of class HttpServletResponse class and using this object response(sent back to browser) parameters can be modified or set.
For e.g. in case of modifying the HTTP headers you can use this object.
Response.setBufferSize(“50”);
Session:
Session object is of class HttpSession and used to maintain the session information. It stores the information in Name-Value pair.
For e.g.
session.setValue(“Name”,”Jakes”);
session.setValue(“Age”,”22”);
Application:
This object belongs to class SevletContext and used to maintain certain information throughout the scope of Application.
For e.g.
Application.setValue(“servername”,”www.myserver.com”);
PageContext:
This object is of class pageContext and is utilized to access the other implicit objects.
Connection Pooling
<%@ page language=" Java " import=" javax.naming.*,javax.sql.*,java.sql.*,java.util.* "%>


<%
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://ramses:7001");
InitialContext ic = new InitialContext(p);
DataSource ds = (DataSource)ic.lookup("demoPool");
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
int i = stmt.executeUpdate(
"insert into employee values('" + empEli.getFirstName() + "','" + empEli.getLastName() + "')" );
}
catch(Exception ex) {
ex.printStackTrace();
}
%>


Employee Firstname is :


Employee Lastname is :


Here we are using the property feature to store all the attributes required to use the connection pool like INITIAL_CONTEXT_FACTORY, PROVIDER_URL.
DataSource ds = (DataSource)ic.lookup("demoPool");
This statement looks up for the connection pool already configured in the particular Application Server. Here the name of the connection pool is named as demoPool .
Connection con = ds.getConnection();
This statement gets hold of an connection to the database from the pool of database connections already existing with the application server.
The rest of the statements are standard JDBC statements used in a normal connection to the database.


 

Rate Tutorial:
http://www.roseindia.net/jsp/jspfundamentals.shtml

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
JSP FUNDAMENTALS

View Tutorial:
JSP FUNDAMENTALS

Related Tutorials:

Which JSP book serves up the best lesson?
Which JSP bookAs for Web servers/databases, just mentioning a server in the book is not sufficient to be listed here.
 
Servlets in Apache Tomcat and BEA Systems' WebLogic Server - JavaWorld February 2001
Servlets in Apache Tomcat and BEA Systems' WebLogic Server - JavaWorld February 2001
 
Master Java with these introductory books - JavaWorld May 2001
Master Java with these introductory books - JavaWorld May 2001
 
JSP 2.0: The New Deal, Part 3
JSP 2.0: The New Deal, Part 3 More Flexible JSP Document Format Rules The JSP specification supports two types of JSP pages: regular JSP pages containing any type of text or markup, and JSP Documents, which are well-formed XML documents; i.e., docum
 
The ABCs of Synchronization, Part 1
Threads may execute in a manner where their paths of execution are completely independent of each other. Neither thread depends upon the other for assistance. For example, one thread might execute a print job, while a second thread repaints a window. And
 
JSP (JavaServer Pages) is a standard for combining Java and HTML to provide dynamic content in web pages.
With JSP, you embed Java code in HTML using special JSP tags similar to HTML tags. You install the JSP page, which has a .jsp extension, into the WebLogic Server document root, just as you would a static HTML page. When WebLogic Server serves a JSP page..
 
BEA WebLogic Portal JSP Tag Libraries
The BEA WebLogic Portal includes four JSP tag libraries that are used by the portal's JSP pages.
 
JSPTags.com offers JSP developers a directory of resources.
JSPTags.com offers JSP developers a directory of resources related to JavaServer Pages, Servlets and Java. As the name JSPTags.com implies, special interest is given to JSP Tag Libraries. Many developers are working with and designing new JSP Tag Librarie
 
JSP Format Bean Library
JSP Format Bean Library is a collection of beans which support Java Server Pages(JSP). JSP allows the HTML developer to embed Java into a page. There are a number of common operations in a scripted page that would be tedious or complex without additional
 
JavaServer Pages Technology - Documentation
Sun's tutorial for Java Server Pages that provide a good introduction to design web pages with JSP.
 
JSP Tutorial
Adding dynamic content via expressionsAs we saw in the previous section, any HTML file can be turned into a JSP file by changing its extension to .jsp. Of course, what makes JSP useful is the ability to embed Java. Put the following text in a file wit
 
JSP Tags
JSP tags do not use <%, but just the < character. A JSP tag is somewhat like an HTML tag. JSP tags can have a "start tag", a "tag body" and an "end tag". The start and end tag both use the tag name, enclosed in < and > characters. The end starts with
 
Advanced Features of JSP Custom Tag Libraries
In this article, the second in the JSP custom tag libraries series, we will cover advanced JSP features and how to use them.
 
Calling JavaBeans from a JSP Page
We will be using this SimpleBean class in this tutorial, so if you haven't read above article then I suggest you do it now.
 
Java Technology Fundamentals
Learn how to use variable arguments lists, the new JConsole utility to monitor applications, and discover ways to learn what you need to know to get Sun certified.
 

JSP Hosting
 
Introduction to the JSP Java Server Pages
Introduction to the JSP Java Server Pages Welcome to JSP Section Introduction To 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
 
JSP Architecture
JSP Architecture JSP ARCHITECTURE J PS pages are high level extension of servlet and it enable the developers to embed java code in html pages. JSP files are finally compiled into a servlet by the JSP engine. Compiled servlet is used by the engine
 
JSP FUNDAMENTALS
JSP FUNDAMENTALS JSP FUNDAMENTALS By: Hrishikesh Deshpande Introduction : JSP termed as Java Server Pages is a technology introduced by Sun Microsystems Inc. to develop the web application in more efficient way than Servlets. It has got many
 
Introduction to JSP Scriptlets
Introduction to JSP Scriptlets INTRODUCTION TO JSP SCRIPTLETS Syntax of JSP Scriptles are: <% //java codes %> JSP Scriptlets begins with <% and ends %> .We can embed any amount of java code in the JSP Scriptlets. JSP Engine places these code
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.