Chapter 1:

 

 

 

Introduction

 

 

   

·      What is JSP ?

·      What is needed in order to develop JSP ?

·      Simple examples of JSP documents

·      Other technologies

 

 

 

 

What is JSP?

 

JSP stands for Java Server Pages. These are (usually) XML\HTML documents that include lines in Java. The standard extension of this kind of files is *.jsp. The JSP file is saved on the server, and when the browser calls it (in a similar way to requests for servlets) the server returns the JSP file response. The request can arrive from an HTML form, from a URL address that was written in the URL line of the browser etc… Generally speaking, the server that receives the request for the JSP file performs the java code and replaces them with their result. Although this is not the most accurate description of the JSP documents way of action, this is their most common way of action. By doing so it is possible to create dynamic HTML documents. Another important feature that the JSP files enable is the use of specific TAGS with special meanings.

 

 

 

What is needed in order to develop JSP documents?

 

First, it is important to mention that the JAVA commands that are written within the JSP files are performed on the server (like servlets) and not on the browser (like applets). For that reason, all the needed classes for developing JSP files should be saved on the server. Therefore, unlike the applets, using servlets & JSP documents is more portable.

 

In order to develop JSP documents there is a need in HTTP server that supports the JSP activation, which means that it has installed a suitable JSP container.

 

 

 

Simple Examples of JSP Documents

 

The following example presents a JSP document that includes several rows in Java, which the server replaces with their outcome (when the server performs them). The following document should be saved in the same library where the HTML files are saved. When HTTP request for that JSP file arrives to the server, the server substitutes them with the result of their activation.

 

 

<!--filename: SimpleJSPDemo.jsp-->

 

 

<!--Copyright (c) 2000 Haim Michael & Zindell Publishing House, Ltd.-->

<!--All rights reserved. No part of the contents of this program may be-->

<!--reproduced or transmitted in any form or by any means without the-->

<!--written permission of the publisher.-->

 

 

<HTML>

 

            <HEAD>

                        <TITLE>SimpleJSPDemo.jsp</TITLE>

            </HEAD>

           

            <BODY>

                        <P>

                        <%      

                                    for(int i=0; i<10; i++)

                                    {

                        %>

                                    Hello Israel !

                                    <BR>

                        <%

                                    }

                        %>

            </BODY>

<HTML>

 

 

The next example presents the possibility to create a JSP document that is activated in a similar way to servlets, from an HTML form. The JSP document receives, from the HTML form, parameter as if it was a servlet. Later, we shall see that a JSP document functionality is achieved using servlets.

 

 

<!—filename: SimpleJSPDemo2HTML.htmlà

 

 

<!—Copyright © 2000 Haim Michael & Zindell Publishing House, Ltd.à

<!—All rights reserved. No part of the contents of this program may beà

<!—reproduced or transmitted in any form or by any means without theà

<!—written permission of the publisher.à

 

 

<HTML>

 

            <HEAD>

                        <TITLE>SimpleJSPDemo2.html</TITLE>

            </HEAD>

           

            <BODY>

                        <P>

                        Please enter the number of loops you want :

                        <FORM METHOD=GET ACTION=”SimpleJSPDemo2.jsp”>

                        <INPUT TYPE=”TEXT” SIZE=”2” NAME=”loopTimes”>

                        <INPUT TYPE=”SUBMIT” VALUE=”ENTER”>

                        </FORM>

            </BODY>

<HTML>

 

 

<!--filename: SimpleJSPDemo2.jsp-->

 

 

<!--Copyright (c) 2000 Haim Michael & Zindell Publishing House, Ltd.-->

<!--All rights reserved. No part of the contents of this program may be-->

<!--reproduced or transmitted in any form or by any means without the-->

<!--written permission of the publisher.-->

 

 

<%@ page language="java" %>

 

<HTML>

 

            <HEAD>

                        <TITLE>SimpleJSPDemo2.jsp</TITLE>

            </HEAD>

           

            <BODY>

                        <P>

                        <%      

                                    int steps = Integer.parseInt(request.getParameter("loopTimes"));

                                    for(int i=0; i<steps; i++)

                                    {

                        %>

                                    Hello Israel !

                                    <BR>

                        <%

                                    }

                        %>

 

            <%@ include file="Rights.html" %>

 

            </BODY>

<HTML>

 

 

<!-- Rights.html -->

 

<HTML>

 

            <HEAD>

                        <TITLE>Rights.html</TITLE>

            </HEAD>

           

            <BODY>

                        <BR>Copyright (c) 2000 Haim Michael & Zindell Publishing House, Ltd.

                        <BR>All rights reserved. No part of the contents of this program may be

                        <BR>reproduced or transmitted in any form or by any means without the

                        <BR>written permission of the publisher.

            </BODY>

           

</HTML>

 

The different JSP tags are presented in the next chapter. The last example shows the usage of two JSP tags:

-       The tag: <%@ page language=”java” %> is used to determine the language which is used in writing the embedded commands.

-       The tag: <%@ include file=”Rights.html” %> is used to embed within the current JSP document another document.

 

When a request for a JSP document arrives to the server for the first time (it is the first time in which the JSP document is requested) the server creates a java source code file with a declaration of a servlet whose result is the result that the JSP document should produce. Later, the server compiles that java source code, instantiate the created class, and invokes the service method on the created object.

 

 

 

Other Technologies

 

The following technologies were designed for similar purposes (comparing to JSP) :

-       CGI

-       SERVLETS

-       ASP

-       ISAPI

-       Java Script on the server side

 

The advantages of using JSP over these other technologies are so obvious that it is redundant describing them.

 

 

 

 

Table of Contents

 

 

Chapter 1:     Introduction

 

Chapter 2:     The Basic Concept

 

Chapter 3:     JSP Expressions

 

Chapter 4:     JSP Scriptlets

 

Chapter 5:     JSP Declarations

 

Chapter 6:     JSP Directives

 

Chapter 7:     Standard JSP Tags (actions)

 

Chapter 8:     Custom JSP Tags (actions)

 

Chapter 9:     JSP Servlets communication

 

Chapter 10:   JSP & JDBC

 

 

 

 

 

 

 

2000 © All the rights reserved to

Haim Michael & Zindell Publishing House Ltd.

 

No parts of the contents of this paper may be reproduced or transmitted

in any form by any means without the written permission of the publisher ! 

This book can be used for personal use only !!!

 

 

 

Brought to you by

 

ZINDELL

 

http://www.zindell.com