Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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

 

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 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=”<Class name>” import=”<class> or <package>”  %>

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=”<filename>” %>

Attributes:

a.     file = “<filename>”

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   <jsp:include page =”<filename>” />

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   <jsp:forward page=”<filename>” />

          This will redirect to the different page without notifying browser.
                      And many more.

Custom Tags:

          taglib

Syntax: <%@ taglib uri=”<tag library uri>” prefix=”<tagprefix>” %>

Attributes:

a. uri = “<relative path of the tag library uri>”
b. prefix = “<tagprefix>”

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.*"%>

 <jsp:useBean id="empEli"  scope = "page" class ="Elitraining.Employee" />
 <jsp:setProperty name ="
empEli" property = "*" />

 <%    

          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();

                    }                                             

%>

<html>

          <body>

Employee Firstname is : <jsp:getProperty name="empEli" property ="firstName" />

<BR>

Employee Lastname is : <jsp:getProperty name="empEli" property ="lastName" />

          </body>

</html>

 

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.
         

                         

» View all related tutorials
Related Tags: java html c web jsp dynamic static script servlet sed ip page tag this log tar close js start technology

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

20 comments so far (
post your own) View All Comments Latest 10 Comments:

how to use in realtime in custom tag and benefits of custom tags and which time for use in custom tags

Posted by saravanan on Monday, 09.22.08 @ 11:02am | #80585

Hi,
I am Manoj undertraining in software job my platform is JAVA plz send more information on JSp

Posted by manoj on Monday, 04.28.08 @ 15:58pm | #58057

Can we learn whole of Java(Core & Advance) by a self study

Posted by prashanthi on Tuesday, 03.4.08 @ 17:49pm | #51306

Hello frends i am fresher and beginer. can guide me how can i got job in java platform. i have learn core java, jsp, servlet only. is it enough for entry. please help me.

Posted by Hiren Patel on Monday, 02.18.08 @ 15:03pm | #48876

The example for connection pooling
jsp:getProperty and jsp:setProperty

how to go whit connection pooling is not mentioned..............some more examples are needed to practice.....retriving, updating,etc....dnamically from database...thankyou if anyone helps


Posted by kiron kumar on Monday, 02.11.08 @ 18:56pm | #47914

hai
i see this website on 1st time its vry useful 2 me. Then u should include in update/new technologies are used in java,jsp,j2ee,j2se,j2me plz sent my id this vry useful 4 my feature carrier.

Posted by shivani on Thursday, 01.31.08 @ 15:03pm | #46715

Dear Sir,

Examples are nice but please mention some more examples of database connectivity specially how to retrieve the values from table by using checkbox and radiobuttons.

Thanks

Kumaril Mishra

Posted by Kumaril Mishra on Wednesday, 01.30.08 @ 14:48pm | #46588

What is computer?

Posted by Nirmal Singh on Thursday, 01.17.08 @ 11:15am | #45408

its good but more description has to be included

Posted by trish on Thursday, 12.6.07 @ 11:20am | #41417

All the definition are superb. But we need Some more jsp programs

Posted by Senthamil Bharathi on Tuesday, 09.25.07 @ 18:36pm | #29327

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.