JSP Standard Action Elements :-


JSP Standard Action Elements are the tags that can be included in JSP files. These action elemnets are converted into java code during translation of JSP files into corresponding servlet that perform the predefines task.
JSP provides the following standard action elements -

;
JSP Action Element Description
jsp:include Used to include other web resources into current jsp file.
jsp:forward Used to forward client request from current jsp file to some other web resource.
jsp:param Used mostly with jsp:include and jsp:forward as nested tag to set parameter (name/value pair).
jsp:useBean Used to define Java Beans in JSP File.
jsp:setProperty Used to set the value of java beans property.
jsp:getProperty Used to get/print the value of java beans property.
jsp:plugin Used to instruct web browser to download java plugin if jsp file contain Java Applets to avoid compatiblity issues. It is replaced by html <object> or <embed> tag depending upon web browser type.
jsp:params Used with jsp:plugin as nested tag. It is optional and if presented must have at last one jsp:param to specify parameter.
jsp:fallback Used with jsp:plugin as nested tag. It is also optional and used to specify a description if plugin could not be started.

<jsp:include> action element -

jsp:include action element is used to include static or dynamic web resources in your current jsp file. It has the following syntax -
<jsp:include page="relativeURL" />        
Where - page attribute specify the url of the web resource you want to include in your jsp page.

We can also send some information in the form of parameters to the included resource using the following syntax -
<jsp:include page="relativeURL" >
<jsp:param name="parameter_name" value="parameter_value />
.........
</jsp:include>  
        
We can specify one or more parameters with jsp:include.

Difference between include page directive and jsp:include

include page directive jsp:include action element
1- It includes the contents of the included file at the time of translation of jsp file into servlet and finally complete contents (jsp orignal content and included file content) executed to generate response. 1- It includes the contents of the included file at the time of execution of jsp file. It behave differently depending upon whether included file is static or dynamic. If included file is static,its content is included in orignal jsp file. If included file is dynamic, the request is send to the included file, its gets executed and its result will be included in response of orignal jsp file.
2- It has the following syntax -
<%@ include file="relativeURL" %>
2- It has the following syntax -
<jsp:include page="relativeURL" />

Example -

This simple example will show you how can we use jsp:include within jsp files.
1- index.jsp - This will be your default page.
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>This is our index.jsp page</h1>
      <jsp:include page="test.jsp">
        <jsp:param name="name" value="rohit kamboj"/>
        </jsp:include>  
    </body>
</html>    

2- test.jsp - Create a test.jsp file as follows -
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
        out.println("<h2>Hello Mr "+request.getParameter("name")+"</h2>");
        out.println("<h3>Today is - </h3>"+new java.util.Date().toString());
        %>
    </body>
</html>        

3- web.xml - Make index.jsp your default page.
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	 version="3.1">
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

4- Now run the project, It will show you the combined output of both index.jsp and test.jsp -



Download this example (NetBeans implementation) - Click Here