Latest Posts
Popular Posts
Main Menu
Home
Travel and Tourism
Media & Entertainment
Telecom & IT
Business and Finance
Sports & Games
Food & Recipe
Health & Medicine
Automobiles
Real Estate
Electronics & Appliances
Forum
Gallery
Casino Games
Business Directory
Festival Special 2011
General Blogs
Sudoku
Free Games
Search

Latest Forum Posts
Topics
How to Fall Asleep Instantly
by sandy
Top 5 Benefits of exercise
by ElizabethScott
Once you pay for the head Kandy exte...
by laowantong
Amy's hair style
by laowantong
What not to put in the fridge
by sandy
Tripod (mainly head opinions)
by Das
Amateur Dslr Users Meetups/ Photo sh...
by sandy
Pets name....
by Weeram
Beginners Astronomy
by sandy
Five surprising things which can har...
by sandy
Entering the world of Web Development~~Part II: PDF Print E-mail
Written by Madhuparna   
Monday, 30 June 2008

www     In the previous article a small introduction was given on what JSP actually is and the necessity of JSP in Web development. With reference to that,some more information will be presented in this article. Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. 

     Before going into detailed discussion on JSP we need to know why should we switch from servlet technology to JSP.

   Difference between Servlet and JSP:      
                                                          
  Servlet
JSP
  ·    HTML code in Java
 Java-like code in HTML
  ·    Not easy to author  Very easy to author
  · 
    Code is compiled into a servlet

    The main difference between servlets and JSPs is that servlets are Java classes and JSPs are not (they are embedded in HTML pages). This difference also specifies where you want to use servlets and where you want to use JSPs: If you generate all of your html pages dynamically and will have complex logic, you will probably use servlets. If dynamic content is very low compared to the static content in your web page, then you will probably use JSPs.

            So far what we have learnt is a request which is to be send to the server and depending on the request,the server processes the request and sends back results again to the receiver. Various web servers or servlet containers are available in market namely Apache Tomcat by Apache,IIS by Microsoft etc.In the following section a brief information regarding installation of Tomcat and its working principle is presented.Our upcoming articles will be based on Tomcat.

Tomcat -   Installation & working

         Tomcat,often referred to as the Tomcat server,is an open-source servlet container and JSP engine.The servlet API and JSP specification designers aim to create,as much as possible,new versions that are backward compatible. When we first start up the Tomcat server,it is operating in standalone mode.Tomcat has a built-in Web server that is used to handle the incoming request from our browser.Along with the Web server,the JSP engine is also started.However the servicing of the initial welcome page does not involve the JSP engine.The JSP page that we see in our browser is stored under the <Tomcat Installation Directory>/webapps/ROOT directory.

   On a Windows system,the downloaded file(by selecting Open or by double-clicking the downloaded Jakarta-tomcat-5.0.28.exe file) is executed.This will start the wizard-based windows installer.The following things should be kept in mind during installation:

·    When the installer asks to choose an installation location,the default folder should be c:\tomcat5 or a similar directory of users choice.

·    When the installer asks to enter configuration options,enter the administration login username of tomcat and choose a password of users choice.

On a Windows system,one should see the Apache Process Runner running on the system tray with a green arrow indicating that Tomcat5 is running.To shut down Tomcat5 on a Windows system,right click the Apache Process Runner on one’s system tray and select Shutdown->Tomcat5.The Apache Process Runner will dissppear from the system tray.

    To verify that the version of Tomcat is installed properly,try to start a browser and access the following URL:

http://localhost:8080/index.jsp

          Having verified that Tomcat5 is correctly installed,it is time to try out some JSP coding.

<%@ taglib prefix=”tags” tagdir=”/WEB-INF/tags” %>

My First JSP 2.0 Template

All I want to say is

Current time is <%=new java.util.date() %>
<html>
<head>
<title>Presenting JSP2.0</title>
</head>
<body>
<h1>My First JSP 2.0 Template</h1>
</hr>
<p>All I want to say is <tags:helloWorld/></p>
<br>
Current time is <%=new java.util.date() %>
</body>
</html>
parna_2008063001.jpg
The above JSP makes use of a special custom tag that simply outputs the text”HelloWorld!”.Within the JSP body,which is essentially an HTML page here,the tag is embedded as follows:
<tags:helloWorld/>
Wherever this helloWorld tag is placed within the JSP,the JSP container will substitute the dynamically generated text “helloWorld!” in its place.

       The rest of the above code contains html statements and tag.A static HTMl file with no dynamic element can be a JSP file. Thus JSP is rightly called a presentation technology.In fact it is possible to have professional Web page designers design the template.The page designer can work on the HTML portion of the template,while the JSP developer can work on the tags used and their placement.If the above sample JSP program is slightly edited & the following modifications are made
 <p>I am so execited,I want to scream “tags:helloWorld/><tags:helloWorld/>
<tags:helloWorld/>”</p>
        In this case the dynamically generated text is repeated.The following o/p is generated:
I am so excited. I want to scream “Hello, world!Hello,world!Hello,world!”

      Because each request is independent,the JSP container is given a chance to determine whether the JSP has been  modified since it was last accessed.If the JSP container detects that the JSP has been modified,the page is recompiled before being used to handle an incoming request.This makes the JSP development cycle quite straight forward;just modify the JSP file and the changes take effect immediately.
The above JSP makes use of a special custom tag that simply outputs the text “Hello World!” Custom tags are collected in a atg library,or taglib for short.To notify the jsp container of the location of the custom tag,a special JSP tag(called the taglib directive) needs to be included:
<%@ taglib prefix=”tags” prefix=”tags” tagdir=”/WEB-INF/tags” %>
In addition the preceding taglib directive also tells Tomcat that all of the tags in this library are prefixed by the word tags.The prefix that is added to the tag to distinguish which library it orginates from is often called the namespace.A detailed understanding of the above code is not possible unless we get acquainted with the elements that make up a JSP page.

      The various elements that make up a JSP page are as follows:
·    Directive element
·    Template element
·    Action
·    Scripting elements

           Detailed discussion on various elements that make a JSP page will be covered in next article. Until then precious comments on the aforesaid article are welcome.

Comments
Add NewSearchRSS
sandy - what is namespace in JSP??? Publisher | 2008-07-03 17:56:44
I often come across this term called namespace. Please somebody explain with example what is this and why this is so common through out all modern languages.
callsamik - Re-Difference between Servlet IP:59.93.254.234 | 2008-07-20 18:08:12
Generally JSPs are used for display the response generated by servlets and all the business logic that creates the respense is implemented by servlets. Though from the user point of view it appears that in JSP we can embed Java into HTML, but in reality all JSP pages are converted to servlets by the web container. Thus JSPs only create some kind of abstraction to help the programmer to generate dynamic web pages with scripting facility.
sandy - basically frontend..isnt it? Publisher | 2008-08-05 18:30:59
JSP is the View in the Model View Controller. Isn't it?
Parna Editor | 2008-08-21 10:51:41
Namespaces allow to group entities like classes, objects and functions under a name. This way the global scope can be divided in "sub-scopes", each one with its own name.
namespace myNamespace
{
int a, b;
}


In this case, the variables a and b are normal variables declared within a namespace called myNamespace. In order to access these variables from outside the myNamespace namespace we have to use the scope operator ::. For example, to access the previous variables from outside myNamespace we can write:

myNamespace::a
myNamespace::b
We find use of namespace in various languages such as Java,C++ etc.Extensive use of namespace is only to access libraries,classes,objects outside its scope to help programmer concentrate more on programming logic instead of syntax.
Parna Editor | 2008-08-21 10:59:20
I truely support the above comment"in reality all JSP pages are converted to servlets by the web container. Thus JSPs only create some kind of abstraction to help the programmer to generate dynamic web pages with scripting facility".Scriplet scripting element which takes an essentital role in the development of JSP page is nothing but pure java code embedded in template data.Attaching attributes to implicit objects is the primary mechanism that enables the diffrenet elements of a JSP page to cooperate and finally the JSP container converts the JSP page into java code before submission to the server.
And sandy i need to go through the topic of Model View controller before answering your query.
Parna - @sandy Editor | 2008-08-27 11:53:28
Model-View-Controller (MVC) is a classic design pattern often used by applications that need the ability to maintain multiple views of the same data. The MVC pattern hinges on a clean separation of objects into one of three categories — models for maintaining data, views for displaying all or a portion of the data, and controllers for handling events that affect the model or view(s).Since JSP is basically used to create various presentations which serves the purpose of view in a model view controller so,JSP can rightly be considered as View in a MVC model
Subhajit - Excellent IP:61.16.236.179 | 2008-08-27 15:44:53
Good discussion .. I am joining later
sandy - thanx subhajit Publisher | 2008-08-27 15:52:35
if possible register yourself first.
Write comment
Name:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
Security Image

Powered by JoomlaCommentCopyright (C) 2006 Frantisek Hliva. All rights reserved.Homepage: http://cavo.co.nr/

Last Updated ( Saturday, 11 December 2010 )
 
< Prev   Next >
Other Articles By Same Author
Related Posts
Advertisement