The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

Including an Applet

You can include an applet or JavaBeans component in a JSP page using the jsp:plugin element. This element generates HTML that contains the appropriate client browser dependent constructs (<object> or <embed>) that will result in the download of the Java Plugin software (if required) and client-side component and subsequent execution of an client-side component. The syntax for the jsp:plugin element follows:

<jsp:plugin 
	type="bean|applet" 
	code="objectCode" 
	codebase="objectCodebase" 
	{ align="alignment" } 
	{ archive="archiveList" } 
	{ height="height" } 
	{ hspace="hspace" } 
	{ jreversion="jreversion" } 
	{ name="componentName" } 
	{ vspace="vspace" } 
	{ width="width" } 
	{ nspluginurl="url" } 
	{ iepluginurl="url" } > 
	{ <jsp:params> 
		{ <jsp:param name="paramName" value= paramValue" /> }+
	</jsp:params> } 
	{ <jsp:fallback> arbitrary_text </jsp:fallback> } 
</jsp:plugin> 

The jsp:plugin tag is replaced by either an <object> or <embed> tag, as appropriate for the requesting client. The attributes of the jsp:plugin tag provide configuration data for the presentation of the element as well as the version of the plugin required. The nspluginurl and iepluginurl attributes specify the URL where the plugin can be downloaded.

The jsp:param elements indicate parameters to the applet or JavaBeans component. The jsp:fallback element indicates the content to be used by the client browser if the plugin cannot be started (either because <object> or <embed> is not supported by the client or due to some other problem).

If the plugin can start but the applet or JavaBeans component cannot be found or started, a plugin-specific message will be presented to the user, most likely a popup window reporting a ClassNotFoundException.

The Duke's Bookstore page banner.jsp that creates the banner displays a dynamic digitial clock generated by DigitalClock:

The jsp:plugin element used to download the applet follows:

<jsp:plugin 
	type="applet" 
	code="DigitalClock.class" 
	codebase="/bookstore2" 
	jreversion="1.3" 
	align="center" height="25" width="300"
	nspluginurl="http://java.sun.com/products/plugin/1.3.0_01/plugin-install.html" 
	iepluginurl="http://java.sun.com/products/plugin/1.3.0_01/jinstall-130_01-win32.cab#Version=1,3,0,1" >
	<jsp:params>
		<jsp:param name="language" value="<%=request.getLocale().getLanguage()%>" />
		<jsp:param name="country" value="<%=request.getLocale().getCountry()%>" />
		<jsp:param name="bgcolor" value="FFFFFF" />
		<jsp:param name="fgcolor" value="CC0066" />
	</jsp:params>
		<jsp:fallback>
		<p>Unable to start plugin.</p>
	</jsp:fallback>
</jsp:plugin> 
Home
TOC
PREV TOC NEXT Search
Feedback