Standard Action in JSP

Introduction

Standard actions in JSP use the <jsp>prefix. The attributes in JSP standard actions are always case-sensitive. Values inside the attributes must be enclosed in double-quotes. Standard actions in JSP can be either a container tag. An empty tag has no body, and it closes within the tag. When a browser requests a JSP page, the typical JSP standard actions are carried out.

<jsp:include>

The include action is used to include the content or insert a file from another HTML or JSP page into the current page. The file is included when the browser requests a JSP page.

Syntax

<jsp:include page=”{relative URL|<%=expression %>}” flush=”true|false”/>
</jsp:include>

In a JSP page, the element <jsp:include> may contain either a static or dynamic file. The results are different when you include static and dynamic files. If it is a static file, then the content is included in the calling JSP page. If it is dynamic, it operates on a request and sends the result that is included in the JSP page. The JSP container continues processing the rest of the JSP page when the included action is finished.

<jsp:include page=”login.php” flush=”true”/>
</jsp:include>

This code shows the example of <jsp:include>; here flush attribute is used to flush the data stored in the buffer before the other response is included.

It is not possible to determine whether the file is static or dynamic from a path name. For example, http://server:8080/index.html may map to a servlet through a server name. When you are ignorant about the type of a file, it is better to use <jsp:include> because it can handle both static and dynamic files.

<jsp:forward>

It is used to forward the request and respond to another JSP or servlet. The control will not come back again to the current JSP.

Syntax

<jsp:forward page=”{relative URL|<%=expression %>}”/>
OR
<jsp:forward page=”{relative URL|<%=expression %>}”>
<jsp:param name=”param Name” value=”{paramvalue/<%=expression%>}”/>
</jsp:forward>

The <jsp:forward> element forwards the request, which contains the client request information, from one JSP Page to another resource, such as an HTML file. JSP page or a servlet. The destination resource must be in the same application context as the forwarding JSP page. In the source JSP page, the contents after the <jsp:forward> element are not processed.

<jsp:forward page=”/servlet/login.jsp”/>
<jsp:forward page=”/servlet/login.html”/>
<jsp:param name=”username” value=”ashish” />
</jsp:forward>

The code shows the example of <jsp:forward>. The page is given as a string, which represents the URL of the destination file. The relative URL never contains a port number or any domain name. To the JSP file, the URL can be absolute or relative. If you use <jsp:forward> with output, which is not buffered, it throws an illegal state exception.

<jsp:plugin>

It is used in the execution of an applet or bean. The applet or bean always executes in the specified plugin. It automatically downloads the plugin software if the plugin is not available.

Syntax

<jsp:plugin
type=”bean/applet”
code=”classFileName”
codebase=”ClassFileDirectoryName”
<jsp:params>
[<jsp:param name=”parameter Name”
value=”{parameter value | <%=expression %>}” />}]
</jsp:params>
[<jsp:fallback>text message for user </jsp:fallback>]</jsp:plugin>

This shows the syntax of <jsp:plugin>. The type specifies the type of object the plug-in execute. It has no default value, so you must specify it either bean or applet.

<jsp:plugin type=applet code=”abc.class”  codebase=”/html”>
<jsp:params>
<jsp:param name=”mca” value=”guide/stud.jsp”/>
</jsp:params>
<jsp:fallback>
<p> Unable to load applet</p>
</jsp:fallback>
</jsp:plugin>

This code shows the example of <jsp:plugin>. The <jsp:plugin> element interacts with the client web browser. Using a Java plugin. When the JSP page sends an HTML response to the client, the <jsp:plugin>element is replaced by either an <object> or <embed> element, according to the version of the browser. For example, the <object> element is defined in HTML 5.0 and <embed> in HTML 4.0

<jsp:param>

It can be used inside a <jsp:include>,<jsp:forward>, or <jsp:params> block. It specifies a parameter that is added to the current parameter of the request.

<jsp:forward page=”forward.jsp”>
<jsp:param name=”forwardedForm” value=”login.php”>
</jsp:forward>

This code shows the <jsp:param> used with the <jsp:forward>. The <jsp:param> allowed you to pass one or more name and value pairs as parameters to an included page. The included page should be dynamic in nature means it can be a JSP page, servlet, or other resources that process the parameter. It is possible to use more than one <jsp:param> if you want to send more parameters to the included resource. The name attribute shows the parameter name. The value attribute shows the parameter value.

<jsp:fallback>

The <jsp:fallback> attribute shows the contents inside it when the browser does not support the applets. It can be used with the <jsp:plugin> and <jsp:param>

<jsp:plugin type=applet height=”100%” width=”100%” archive=”myjarfile.jar, myotherjar.jar”
codebase=”applets” code=”com.applet”>
<jsp:params>
<jsp:param name=”enable Debug” value=”true”/>
</jsp:params>
<jsp:fallback>
Your Browser does not support applets.
</jsp:fallback>
</jsp:plugin>

This code shows the use of <jsp:fallback> when the browser did not get any applet.

Summary

JSP's default action prefix is <jsp>. There is no case insensitivity for the attributes in JSP standard actions.


Similar Articles