

{"id":80139,"date":"2020-08-28T09:00:12","date_gmt":"2020-08-28T03:30:12","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=80139"},"modified":"2021-08-25T13:47:43","modified_gmt":"2021-08-25T08:17:43","slug":"jsp-actions","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/jsp-actions\/","title":{"rendered":"JSP Actions &#8211; JSP Action Tags, Syntax and Examples"},"content":{"rendered":"<p>JSP Actions are one of the three important elements of a JSP page. They perform some specific tasks and are predefined. They provide functionalities like-<\/p>\n<ul>\n<li>Dynamic insertion of a file<\/li>\n<li>Controlling behavior of the servlet engine<\/li>\n<li>Forwarding a user to another page<\/li>\n<li>Controlling flow between pages<\/li>\n<\/ul>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81326\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg\" alt=\"JSP Actions\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions-1024x536.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions-520x272.jpg 520w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/p>\n<h2>JSP Actions<\/h2>\n<p>XML format is used to define JSP Actions. What makes them different from directives is that each time a page is visited, if it contains actions then those actions get re-evaluated.<\/p>\n<p><strong>Common Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:action_name attribute=\u201dvalue\u201d\/&gt;<\/pre>\n<p>There are in all eleven JSP action tags. They are:<\/p>\n<ul>\n<li>jsp:include<\/li>\n<li>jsp:useBean<\/li>\n<li>jsp:setProperty<\/li>\n<li>jsp:getProperty<\/li>\n<li>jsp:forward<\/li>\n<li>jsp:plugin<\/li>\n<li>jsp:body<\/li>\n<li>jsp:text<\/li>\n<li>jsp:element<\/li>\n<li>jsp:param<\/li>\n<li>jsp:attribute<\/li>\n<li>jsp:output<\/li>\n<\/ul>\n<p>Before discussing these JSP actions, there are two important attributes that are common to all actions. They are id and scope. id refers the object uniquely created by actions, scope tells about the life of that object. The scope attribute has four values. They are page, application, session, and request.<\/p>\n<h3>1. &lt;java:include&gt;<\/h3>\n<p>This action will include the required resources like html, servlets and JSP.<br \/>\nThis jsp:include action is different from jsp directive. Include directive includes resources at the time of translation, whereas include action includes resources dynamically at request time. Action directives work well for static pages, whereas later works better for dynamic pages.<br \/>\nThere are two attributes under include:<\/p>\n<ul>\n<li><strong>Page:<\/strong> its value is the url of the required resource.<\/li>\n<li><strong>Flush:<\/strong> it checks that the buffer of the resource is flushed before it is included.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:include page=\"page URL\" flush=\"true\/false\"&gt;<\/pre>\n<p><strong>Advantages of include actions are:<\/strong><\/p>\n<ul>\n<li>It is best for dynamic pages.<\/li>\n<li>It promotes code reusability as we include pages<\/li>\n<li>This saves time as we can use one page again and again.<\/li>\n<li>It can be created with or without parameters.<\/li>\n<\/ul>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Main.jsp\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n &lt;title&gt;JSP Actions&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h3&gt;--DataFlair--&lt;\/h3&gt;\r\n&lt;jsp:include page=\"date.jsp\" flush=\"true\" \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n \r\ndate.jsp\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n \r\n&lt;title&gt;JSP Actions&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;p&gt;\r\nToday's date: &lt;%= (new java.util.Date()).toLocaleString()%&gt;\r\n&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nIn this example we can see that main.jsp includes date.jsp that gives date and time, whereas date.jsp contains the code to retrieve the date.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81327\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1.png\" alt=\"jsp actions\" width=\"1366\" height=\"170\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1-300x37.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1-1024x127.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1-150x19.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1-768x96.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-1-520x65.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>2. &lt;jsp:usebean&gt;<\/h3>\n<p>If we want to instantiate bean (many objects encapsulated in one object) class in our JSP page, then this action comes into play. It has following attributes:<\/p>\n<ul>\n<li><strong>id:<\/strong> id uniquely identifies bean in a specified scope.<\/li>\n<li><strong>Scope<\/strong><\/li>\n<\/ul>\n<blockquote>\n<ol>\n<li>Page: It is the default scope that states that we can use bean within this JSP page.<\/li>\n<li>Request: It is broader than a page as bean can be used from any page that processes similar requests.<\/li>\n<li>Session: It has a wider range than above as bean can be used from any page in the same session.<\/li>\n<li>Application: It has the maximum range as bean can be used from any page present in the same application.<\/li>\n<\/ol>\n<\/blockquote>\n<ul>\n<li><strong>Class:<\/strong> Creates object of bean class.<\/li>\n<li><strong>Type:<\/strong> It gives the data type to the bean existing in the specified scope. It is used with class and beanName.<\/li>\n<li><strong>beanName:<\/strong> Uses the java.beans.Beans.instantiate() method and instantiates bean.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:useBean id= \"bean\"  scope= \"page\/(session\/request\/application)\"  \r\nclass= \"package.class\"  type= \"package.class\" \r\nbeanName=\"package.class &gt; \r\n&lt;\/jsp:useBean&gt;\r\n<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">square.java\r\nPackage demotest;\r\npublic class square\r\n{ \r\n  public int square(int n)\r\n      \t{return n*n;} \r\n} \r\n \r\nexample.jsp\r\n&lt;html&gt;\r\n&lt;title&gt;usebean&lt;\/title&gt;\r\n&lt;body&gt;\r\n&lt;jsp:useBean id=\"obj\" class=\"demotest.square\"\/&gt; \r\n  &lt;% \r\nint m=obj.square(3); \r\nout.print(\"square of 3 is \"+m); \r\n%&gt; \r\n&lt;\/body&gt;&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nIn the java file square.java we prepare a basic class and in jsp file we invoke useBean. The object is thus instantiated, referenced through id. We generate the square of the given number.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81329\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act3.png\" alt=\"jsp usebean\" width=\"133\" height=\"47\" \/><\/a><\/p>\n<h3>3. &lt;jsp:setProperty&gt;<\/h3>\n<p>jsp:setProperty and getProperty are used with usebeans. It is used to modify the properties of beans. It gets executed when new objects are created.<\/p>\n<p>This has four attributes:<\/p>\n<ul>\n<li><strong>name:<\/strong> It is literally the name of the bean whose property we want to set. It has the same name as the object we instantiated using usebean.<\/li>\n<li><strong>property:<\/strong> sets the property of the bean \u201c*\u201d means all the requests that match bean properties are included.<\/li>\n<li><strong>value:<\/strong> gives specific value to the bean.<\/li>\n<li><strong>Param:<\/strong> a name that will fetch the value .<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:setProperty name=\u201cbean\u201d property= \u201c*\u201d|\r\nproperty=\u201cpropertyName\u201d value= \u201c&lt;%=expression&gt;\u201d|\r\nproperty=\u201cpropertyName\u201d param= \u201cParametername\u201d\r\n<\/pre>\n<p>**Example with get property<\/p>\n<h3>4. &lt;java:getProperty&gt;<\/h3>\n<p>This action gets the value of the property and gives it out on the output as a string.<br \/>\nTo get the property of a bean, bean and its name must be defined. Our main purpose is to get the value of the property where the property is the name of the bean property that was set by setProperty as well. The attributes used by getProperty are<\/p>\n<ul>\n<li><strong>name:<\/strong> It gets the name of the bean whose property we need to get as its value.<\/li>\n<li><strong>property:<\/strong> It defines the name of the property required for the bean.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:setProperty name=\"bean\" property=\"message\" value=\"Myexample\" \/&gt;\r\n&lt;jsp:getProperty name=\"MyPage\" property=\"message\" \/&gt;\r\n<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">TestBean.java\r\npackage demotest;\r\nimport java.io.Serializable;\r\npublic class TestBean implements Serializable\r\n {\r\nprivate String message = \"null\";\r\n \r\n \tpublic String getMessage() {\r\n \t return msg;\r\n }\r\n \r\n \tpublic void setMessage(String message) {\r\n  \tthis.message = message;\r\n }\r\n}\r\n\r\nGetSet.jsp\r\n&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\"\r\n  pageEncoding=\"ISO-8859-1\"%&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Get Set Property&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;jsp:useBean id=\"myBean\" class=\"demotest.TestBean\" \/&gt;\r\n&lt;jsp:setProperty name=\"myBean\" property=\"message\" value=\"GetSetActions\" \/&gt;\r\n&lt;jsp:getProperty name=\"myBean\" property=\"message\" \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nFirstly, a TestBean class of package demotest that implements serializable class has been defined that gets and sets the message using getters and setters.<\/p>\n<p>In jsp code, we used useBean action that will instantiate the object myBean. Then we set the property of the object and give it a value \u201cGetSetAction\u201d. Thereafter, using getProperty we fetch the value for myBean that was set as GetSetAction as our output.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81333\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1.png\" alt=\"\" width=\"1366\" height=\"144\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1-300x32.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1-1024x108.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1-150x16.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1-768x81.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/image7-1-520x55.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>5. &lt;jsp:forward&gt;<\/h3>\n<p>This action as the name suggests forwards the request to another page. This other page may be static as well as a JSP page.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">main.jsp\r\n&lt;jsp:forward =\u201cotherpage.jsp\u201d&gt;\r\n<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">Forward.jsp\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;JSP Forward&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;a&gt;I was the requested page but forwarded the request to other&lt;\/a&gt;\r\n&lt;jsp:forward page=\"other.jsp\" \/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n \r\nOther.jsp\r\n&lt;html&gt;\r\n&lt;title&gt;JSP Forward 2&lt;\/title&gt;\r\n&lt;h3&gt;DataFlair&lt;\/h3&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;a&gt;I am the other page where request is forwarded.&lt;\/a&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> User calls main.jsp but gets forwarded to other.jsp<\/p>\n<p><strong>Output:<\/strong><\/p>\n<h3><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81328\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2.png\" alt=\"jsp usebean\" width=\"1366\" height=\"164\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2-300x36.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2-1024x123.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2-150x18.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2-768x92.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions2-520x62.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/h3>\n<h3>6. &lt;jsp:plugin&gt;<\/h3>\n<p>Plugin inserts java objects or embed tags into a JSP page. It has three attributes:<\/p>\n<ul>\n<li><strong>type:<\/strong> applet\/bean<\/li>\n<li><strong>code:<\/strong> It is the name of the class file.<\/li>\n<li><strong>codebase:<\/strong> It is the directory of the name of the class file.<\/li>\n<\/ul>\n<p><strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:plugin type=\"bean\/applet\" code=\"className\" codebase=\"package.class\"&gt;\r\n<\/pre>\n<p>**Example of plugin with param<\/p>\n<h3>7. &lt;jsp:param&gt;<\/h3>\n<p>It sends parameters to a bean or applet. It can also be said as the child object of a plugin.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:params&gt;\r\n&lt;jsp:param name=\u201c__\u201d value=\"__\"\/ &gt;\r\n&lt;\/jsp:params&gt;\r\n<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">First.jsp\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Plugin Param &lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;jsp:plugin type=\"bean\" code=\"colour.class\" codebase=\"demotest.colour\"&gt;\r\n  &lt;jsp:params&gt;\r\n     &lt;jsp:param name=\"id\" value=\"5\" \/&gt;\r\n     &lt;jsp:param name=\"nameofcolour\" value=\"red\" \/&gt;\r\n  &lt;\/jsp:params&gt;\r\n&lt;\/jsp:plugin&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n \r\nColour.java\r\n package demotest;\r\nimport java.io.Serializable;\r\npublic class Colour implements Serializable {\r\n \t\r\n \tpublic String getName () {\r\n          \treturn name;\r\n \t}\r\n \tpublic void setName (String name) {\r\n          \tthis.name = name;\r\n \t}\r\n \tpublic int getId() {\r\n          \treturn id;\r\n \t}\r\n \tpublic void setId (int id) {\r\n          \tthis.id = id;\r\n \t} \/\/getters and setters\r\n \tprivate String name = \"null\";\r\n \tprivate int id = 0;\r\n \t\r\n}\r\n\r\n<\/pre>\n<p><strong>Explanation:<\/strong> In the First.jsp we are using plugin attributes type, code and codebase. In that we are having param child objects that get the name and value for the plugin. Whereas in Colour.java, we have used getters and setters to get and set the values of name and id.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81332\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6.png\" alt=\"\" width=\"1366\" height=\"120\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6-300x26.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6-1024x90.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6-150x13.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6-768x67.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/act6-520x46.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>8. &lt;jsp:body&gt;and &lt;jsp:element&gt;<\/h3>\n<p>In the body part of this action, we can define XML. Elements will be generated at runtime i.e. dynamically.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:body&gt;.....\r\n    &lt;\/jsp:body&gt;\r\n<\/pre>\n<p>**Example of element, attribute, body together below.<\/p>\n<h3>9. &lt;jsp:attribute&gt;&lt;\/jsp:attribute&gt;<\/h3>\n<p>Once XML is defined, we can also define its attribute dynamically.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:attribute name=\"Put your XMLattribute here..\"&gt; &lt;\/jsp:attribute&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n&lt;head&gt;&lt;title&gt;ele attr body&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;jsp:element name=\"XMLelement\"&gt;\r\n&lt;jsp:attribute name=\"XMLattribute\"&gt;\r\n&lt;\/jsp:attribute&gt;\r\n&lt;jsp:body&gt; My XML&lt;\/jsp:body&gt;\r\n&lt;\/jsp:element&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong><br \/>\nThis code contains the example of element, attribute, body of a dynamically generated HTML.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81330\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4.png\" alt=\"jsp get set\" width=\"1366\" height=\"132\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4-300x29.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4-1024x99.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4-150x14.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4-768x74.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-4-520x50.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>10. &lt;jsp:text&gt;<\/h3>\n<p>It will contain the template data. It can have either text or EL expressions.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:text&gt; Enter your text here\u2026&lt;\/jsp:text&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Template&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;jsp:text&gt;Here goes the template text.&lt;\/jsp:text&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> Under jsp:text action we can output the template text.<\/p>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-81331\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5.png\" alt=\"\" width=\"1366\" height=\"136\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5-300x30.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5-1024x102.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5-150x15.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5-768x76.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/Actions-5-520x52.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h3>11. &lt;jsp:output&gt;<\/h3>\n<p>JSP output contains two attributes i.e doctype-root-element that will possess the root element of the generated XML and doctype-system that shows doctype that will be generated in output.<br \/>\n<strong>Syntax:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;jsp:output doctype-root-element=\"__\" doctype-system=\"__\"&gt;<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Output Actions&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;jsp:output doctype-root-element=\"XML\" doctype-system=\"http:\/\/www.myxml.com\/loose.dtd\"\/&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Explanation:<\/strong> This output is generated internally thus we can\u2019t infer output<\/p>\n<h2>Conclusion<\/h2>\n<p>In reference to this article, we came to know about different action tags, their attributes and values. They are written in XML format. They stimulate the behaviour of the servlet engine and perform specific tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JSP Actions are one of the three important elements of a JSP page. They perform some specific tasks and are predefined. They provide functionalities like- Dynamic insertion of a file Controlling behavior of the&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":81326,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22403],"tags":[22927,23072,23073],"class_list":["post-80139","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp","tag-jsp-action-tags","tag-jsp-actions","tag-jsp-attributes"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JSP Actions - JSP Action Tags, Syntax and Examples - DataFlair<\/title>\n<meta name=\"description\" content=\"JSP Actions - Learn different JSP action tags, their attributes &amp; values. They are written in XML format &amp; stimulate behaviour of servlet engine.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/jsp-actions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSP Actions - JSP Action Tags, Syntax and Examples - DataFlair\" \/>\n<meta property=\"og:description\" content=\"JSP Actions - Learn different JSP action tags, their attributes &amp; values. They are written in XML format &amp; stimulate behaviour of servlet engine.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/jsp-actions\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-28T03:30:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T08:17:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSP Actions - JSP Action Tags, Syntax and Examples - DataFlair","description":"JSP Actions - Learn different JSP action tags, their attributes & values. They are written in XML format & stimulate behaviour of servlet engine.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/jsp-actions\/","og_locale":"en_US","og_type":"article","og_title":"JSP Actions - JSP Action Tags, Syntax and Examples - DataFlair","og_description":"JSP Actions - Learn different JSP action tags, their attributes & values. They are written in XML format & stimulate behaviour of servlet engine.","og_url":"https:\/\/data-flair.training\/blogs\/jsp-actions\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-08-28T03:30:12+00:00","article_modified_time":"2021-08-25T08:17:43+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"JSP Actions &#8211; JSP Action Tags, Syntax and Examples","datePublished":"2020-08-28T03:30:12+00:00","dateModified":"2021-08-25T08:17:43+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/"},"wordCount":1153,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg","keywords":["JSP Action Tags","JSP Actions","jsp attributes"],"articleSection":["JSP Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/jsp-actions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/","url":"https:\/\/data-flair.training\/blogs\/jsp-actions\/","name":"JSP Actions - JSP Action Tags, Syntax and Examples - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg","datePublished":"2020-08-28T03:30:12+00:00","dateModified":"2021-08-25T08:17:43+00:00","description":"JSP Actions - Learn different JSP action tags, their attributes & values. They are written in XML format & stimulate behaviour of servlet engine.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/jsp-actions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/08\/JSP-Actions.jpg","width":1200,"height":628,"caption":"JSP Actions"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/jsp-actions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"JSP Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/jsp\/"},{"@type":"ListItem","position":3,"name":"JSP Actions &#8211; JSP Action Tags, Syntax and Examples"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team is passionate about delivering top-notch tutorials and resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With expertise in the tech industry, we simplify complex topics to help learners excel. Stay updated with our latest insights.","url":"https:\/\/data-flair.training\/blogs\/author\/dfadteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/80139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=80139"}],"version-history":[{"count":4,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/80139\/revisions"}],"predecessor-version":[{"id":81336,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/80139\/revisions\/81336"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/81326"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=80139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=80139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=80139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}