From Twitter

INCLUDING FILES AND APPLETS IN JSP DOCUMENTS

INCLUDING FILES AND APPLETS IN JSP

DOCUMENTS

Now in this section, we learn how to include external pieces into a JSP document. JSP
has three main capabilities for including external pieces into a JSP document.

i) jsp:include action
 
This includes generated page, not JSP code. It cannot access environment of main
page in included code.

 ii) include directive
 
Include directive includes dynamic page, i.e., JSP code. It is powerful, but poses
maintenance challenges.
 

iii) jsp:plugin action
 
This inserts applets that use the Java plug-in. It increases client side role in dialog.
Now, we will discuss in details about this capability of JSP.

 • Including Files at Page Translation Time

  You can include a file with JSP at the page translation time. In this case file will be
included in the main JSP document at the time the document is translated into a
servlet (which is typically the first time it is accessed).
To include file in this way, the syntax is:
 
<%@ include file= “Relative URL” %>
 
There are two consequences of the fact that the included file is inserted at page
translation time, not at request time as with jsp: include.
 
First, you include the actual file itself, unlike with jsp:include , where the server runs
the page and inserts its output. This approach means that the included file can contain
JSP constructs (such as field or method declarations) that affect the main page as a.
 whole.

Second, if the included file changes, all the JSP files that use it need to be updated.

• Including Files at Request Time


As you studied, the include directive provides the facility to include documents that
contain JSP code into different pages. But this directive requires you to update the
modification date of the page whenever the included file changes, which is a
significant inconvenience.
 
Now, we will discuss about the jsp:include action. It includes files at the time of the
client request and thus does not require you to update the main file when an included
file changes. On the other hand, as the page has already been translated into a servlet
at request time, thus the included files cannot contain JSP.
 
Although the included files cannot contain JSP, they can be the result of resources that
use JSP to create the output. That is, the URL that refers to the included resource is
interpreted in the normal manner by the server and thus can be a servlet or JSP page.
This is precisely the behaviour of the include method of the RequestDispatcher class,
which is what servlets use if they want to do this type of file inclusion.
The jsp:include element has two required attributes (as shown in the sample below),
these elements are:
 
  1. i) page : It refers to a relative URL referencing the file to be included
     
  2. ii) flush: This must have the value true. <jsp:include page="Relative URL" flush="true" />



Although you typically include HTML or plain text documents, there is no
requirement that the included files have any particular file extension.

  • • Including Applets for the Java Plug-In

To include ordinary applets with JSP, you don’t need any special syntax; you need to
just use the normal HTML APPLET tag. But, these applets must use JDK 1.1 or JDK
1.02, because neither Netscape 4.x nor Internet Explorer 5.x support the Java 2
platform (i.e., JDK 1.2). This lack of support imposes several restrictions on applets
these are:
  • • In order to use Swing, you must send the Swing files over the network. This process is time consuming and fails in Internet Explorer 3 and Netscape 3.x and 4.01-4.05 (which only support JDK 1.02), since Swing depends on JDK 1.1. 
  • You cannot use Java 2D.
  • You cannot use the Java 2 collections package
  • your code runs more slowly, since most compilers for the Java 2 platform are significantly improved over their 1.1 predecessors.
 To solve this problem, Sun developed a browser plug-in for Netscape and Internet
Explorer that lets you use the Java 2 platform for applets in a variety of browsers
a reasonable alternative for fast corporate intranets, especially since applets can
automatically prompt browsers that lack the plug-in to download it. But, since, the
plug-in is quite large (several megabytes), it is not reasonable to expect users on th
WWW at large to download and install it just to run your applets. As well as, the
normal APPLET tag will not work with the plug-in, since browsers are specifically
designed to use only their built-in virtual machine when they see APPLET. Instead,
you have to use a long and messy OBJECT tag for Internet Explorer and an equally
long EMBED tag for Netscape. Furthermore, since, you typically don’t know which
browser type will be accessing your page, you have to either include both OBJECT
and EMBED (placing the EMBED within the COMMENT section of OBJECT) oridentify the browser type at the time of the request and conditionally build the right tag .This process is straightforward but tedious and time consuming.
The jsp:plugin element instructs the server to build a tag appropriate for applets that
use the plug-in. Servers are permitted some leeway in exactly how they impliment
this support, but most simply include both OBJECT and EMBED

The simplest way to use jsp:plugin is to supply four attributes: type, code, width, and
height. You supply a value of applet for the type attribute and use the other three
attributes in exactly the same way as with the APPLET element.with two exception
i.e., the attribute names are case sensitive and single or double quotes are always
required around the attribute values
for example, you could replace

<APPLET CODE=MyApplet.class” WIDTH=475 HEIGHT=350>
</APPLET>
with
<jsp.plugintype="applet" code="MyApplet.class" width="475"
height="350">
</jsp:plugin>
The jsp:pluginelement has a number of other optional attributes. A list of these
attributes is:

 

•   type:

For applets, this attribute should have a value of applet. However, the Java Plug-In
also permits you to embed JavaBeans elements in Web pages. Use a value of bean i
such a case

• code :

This attribute is used identically to the CODE attribute of APPLET, specifying the
top-level applet class file that extends Applet or JApplet. Just remember that the name
code must be lower case with jsp:plugin (since, it follows XML syntax), whereas with
APPLET, case did not matter (since, HTML attribute names are never case sensitive).
 

• width :


This attribute is used identically to the WIDTH attribute of APPLET, specifying the
width in pixels to be reserved for the applet. Just remember that you must enclose the
value in single or double quotes.
 

• height :


This attribute is used identically to the HEIGHT attribute of APPLET, specifying the
height in pixels to be reserved for the applet. Just remember that you must enclose the
value in single or double quotes.
 

• codebase :

This attribute is used identically to the CODEBASE attribute of APPLET, specifying
the base directory for the applets. The code attribute is interpreted relative to this
directory. As with the APPLET element, if you omit this attribute, the directory of the
current page is used as the default. In the case of JSP, this default location is the
directory where the original JSP file resided, not the system-specific location of the
servlet that results from the JSP file.
 

• align:


This attribute is used identically to the ALIGN attribute of APPLET and IMG,
specifying the alignment of the applet within the web page. Legal values are left,
right, top, bottom, and middle. With jsp:plugin, don’t forget to include these values in
single or double quotes, even though quotes are optional for APPLET and IMG.
 

• hspace :


This attribute is used identically to the HSPACE attribute ofAPPLET, specifying
empty space in pixels reserved on the left and right of the applet. Just remember that
you must enclose the value in single or double quotes.
 

• vspace :


This attribute is used identically to the VSPACE attribute of APPLET, specifying
empty space in pixels reserved on the top and bottom of the applet. Just remember that
you must enclose the value in single or double quotes.
 

• archive :


This attribute is used identically to the ARCHIVE attribute of APPLET, specifying a
JAR file from which classes and images should be loaded.


 • name :


This attribute is used identically to the NAME attribute of APPLET, specifying a
name to use for inter-applet communication or for identifying the applet to scripting
languages like JavaScript

 • title :


This attribute is used identically to the very rarely used TITLE attribute of APPLET
(and virtually all other HTML elements in HTML 4.0), specifying a title that could be
used for a tool-tip or for indexing.
 

• jreversion :


This attribute identifies the version of the Java Runtime Environment (JRE) that is
required. The default is 1.1.
 

• iepluginurl :


This attribute designates a URL from which the plug-in for Internet Explorer can be
downloaded. Users who don’t already have the plug-in installed will be prompted to
download it from this location. The default value will direct the user to the Sun site,
but for intranet use you might want to direct the user to a local copy.
 

• nspluginurl :


This attribute designates a URL from which the plug-in for Netscape can be
downloaded. The default value will direct the user to the Sun site, but for intranet use
you might want to direct the user to a local copy.
 

The jsp:param and jsp:params Elements


The jsp:param element is used with jsp:plugin in a manner similar to the way that
PARAM is used with APPLET, specifying a name and value that are accessed from
within the applet by getParameter. There are two main differences between jsp:param
and param with applet, these are :
 
First, since jsp:param follows XML syntax, attribute names must be lower case,
attribute values must be enclosed in single or double quotes, and the element must end
with />, not just >.
 
Second, all jsp:param entries must be enclosed within a jsp:params element.
So, for example, you would replace
 
<APPLET CODE= “MyApplet.class” WIDTH=475 HEIGHT=350>
<PARAM NAME=“PARAM1” VALUE= “VALUE1”>
<PARAM NAME= “PARAM2” VALUE= “VALUE2”>
</APPLET>
with
<jsp:plugin type= “applet” code= “MyApplet.class” width= “475” height=“350”>
<jsp:params>
<jsp:param name=“PARAM1” value= “VALUE1” />
<jsp:param name= “PARAM2” value=“VALUE2” />
</jsp:params>
</jsp:

 The jsp:fallback Element


The jsp:fallback element provides alternative text to browsers that do not support
OBJECT or EMBED. You use this element in almost the same way as you would use
alternative text placed within an APPLET element.
So, for example, you would replace
 
<APPLET CODE=“MyApplet.class” WIDTH=475 HEIGHT=350>
<B>Error: this example requires Java.</B>
</APPLET>
with
<jsp:plugin type=“applet” code= “MyApplet.class” width=“475” height=“350”>
<jsp:fallback>
<B>Error: this example requires Java.</B>
</jsp:fallback>
 </jsp:plugin


No comments:

Post a Comment

Labels

(MCS-031 (6) 2011 (5) 4nf (1) 5nf (1) ACCESS CONTROL In Relational Database (1) ALGORITHMICS (5) assignment 2014 2015 (1) AVAILABLE TOOLS & ALGORITHMS (5) BCA (1) BINARY SEARCH (1) Block Nested Loop Join (1) Build and Fix Model (1) BUILDING BLOCKS OF ALGORITHMS (1) CHARACTERISTICS OF AN ALGORITHM (2) Core Java (1) Data Communication Network Security (1) DATABASE SECURITY (1) EER tool (1) ELEMEMTARY ALGORITHMICS (2) ENHANCED ER TOOLS (1) EVOLUTION (1) EXAMPLE OF AN ALGORITHM (2) Indexed Nested-Loop Join (1) install servelet engine (1) INTRODUCTION (1) Iterative Enhancement Model (1) Java Server Pages (1) JDBC (1) JSP (2) LEVELS OF DATABASE SECURITY (1) MCA (9) MCA 051 (1) MCA 3rd Semester (8) MCA 4th Semester (1) MCA 5 sem (1) MCS-031 (7) MCS-031 : DESIGN AND ANALYSIS OF ALGORITHM (14) MCS-032 (1) MCS-033 (1) MCS-034 (2) MCS-035 (1) mcs-041 (2) MCS-042 (1) mcs-043 (2) mcs-052 solved assignment (1) MCSL-036 (2) Nested loop join (1) OBJECTIVES (1) Operating System (2) OUTLINE OF ALGORITHMICS (1) Principles of Management and Information Systems (1) PROBLEMS (1) QUERY PROCESSING AND EVALUATION (1) Query processing Optimisation (1) Question Papers (8) Related Topic (9) relational Database (1) SELECT OPERATION Query Processing (1) Servlet (1) Servlet Programme (1) Servlet Programming (1) SOFTWARE DEVELOPMENT MODELS (4) SOFTWARE ENGINEERING (4) Solution (7) Solved Assignment 2013 2014 (6) SOME PRE-REQUISITES AND Asymptotic Bounds ASYMPTOTIC BOUNDS INTRODUCTION (1) STATISTICAL DATABASE SECURITY (1) structure (1) SUMMARY (1) Waterfall Model (1) Write a C program to print the following triangle (1)