Syntax: In this tutorial, you will learn about JSP Standard Actions. JSP Standard Action tags are used for controlling the behavior of servlet engine.

jsp:useBean

This action name is used when we want to use beans in the JSP page. With this tag, we can easily invoke a bean.

Syntax of jsp: UseBean:

jsp:useBean jsp:include jsp:setProperty jsp:getProperty jsp:forward jsp:plugin jsp:attribute jsp:body jsp:text jsp:param jsp:attribute jsp:output

Here it specifies the identifier for this bean and class is full path of the bean class Example: Explanation of the code: Code Line 10: In the above code we use “bean id” and “class path” of the bean.

jsp:include

It also used to insert a jsp file into another file, just like including Directives. It is added during request processing phase

Syntax of jsp:include Example: Action_jsp2 (Code Line 10) we are including a date.jsp file Date.jsp Explanation of the code: Action_jsp2.jsp Code Line 10: In the first file we are including the date.jsp file in action_jsp2.jsp Date.jsp: Code Line 11: We are printing today’s date in code line 11 in date.jsp When you execute the code following is the output.

Output:

It displays today’s date with time as date file is included in the main jsp

jsp:setProperty

This property of standard actions in JSP is used to set the property of the bean. We need to define a bean before setting the property

Syntax: Here, the name defines the bean whose property is set and property which we want to set. Also, we can set value and param attribute. Here value is not mandatory, and it defines the value which is assigned to the property. Here param is the name of the request parameter using which value can be fetched. The example of setproperty will be demonstrated below with getproperty

jsp:getProperty

This property is used to get the property of the bean. It converts into a string and finally inserts into the output.

Syntax: Here, the name of the bean from which the property has to be retrieved and bean should be defined. The property attribute is the name of the bean property to be retrieved. Example of setProperty and getProperty: TestBean.java: Action_jsp3.jsp Explanation of the code: TestBean.java: Code Line 5: TheTestBean is implementing the serializable class. It is a bean class with getters setters in the code. Code Line 7: Here we are taking private string variable msg as “null” Code Line 9-14: Here we are using getters and setters of variable “msg”. Action_jsp3.jsp Code Line 10: Here we are using “useBean” tag, where it specifies the bean i.e TestBean which has to be used in this jsp class Code Line 11: Here we are setting the value for the property msg for bean TestBean as “GuruTutorial.” CodeLine12: Here using getProperty, we are getting the value of property msg for bean TestBean i.e GuruTutorial which is there in the output When you execute the above code you get the following output:

Output: In this example, using TestBean we are trying to set the property “gurutest” using setProperty and get the value of property using getProperty as “GuruTutorial”

jsp:forward

It is used to forward the request to another jsp or any static page. Here the request can be forwarded with no parameters or with parameters. Syntax: Here value represents where the request has to be forwarded. Example: Action_jsp41.jsp Jsp_action_42.jsp Explanation of the code Action_jsp41.jsp Code Line 10: Here we are using forward JSP Action to forward the request to the page mentioned in the attribute, i.e., jsp_action_42.jsp Jsp_action_42.jsp Code Line 10: Once we call action_jsp41.jsp, the request gets forwarded to this page, and we get the output as “This is after forward page.” When we execute the above code, we get the following output

Output: We call action_jsp41.jsp but the request gets forwarded to jsp_action_42.jsp, and we get the output from that page as “This is after forward page”.

jsp:plugin

It is used to introduce Java components into jsp, i.e., the java components can be either an applet or bean. It detects the browser and adds orJSP tags into the file

Syntax:

Here the type specifies either an object or a bean Code specifies class name of applet or bean Code base contains the base URL that contains files of classes

jsp:param

This is child object of the plugin object described above It must contain one or more actions to provide additional parameters.

Syntax: Example of plugin and param Action_jsp5.jsp Student.java Explanation of the code: Action_jsp5.jsp Code Line 10: Here we are taking jsp: plugin object where we are taking three attributes

Type – in this case it is bean Code- name of the file Codebase – path with the package name

Code Line 11-14: Here we are taking jsp: params object under which there is a child param object with the attributes of name and value, and we are setting the values of id and name in this attributes. Student.java Code 7- 17: We are using getters and setters for variables id and name Code 19-20: we are initializing variables id and name. Here we will get output in the case when the set values of param will be used in Student Bean. In this case, we won’t have any output as we are just setting and getting values of param but not printing it anywhere.

jsp:body

This tag is used to define the XML dynamically i.e., the Elements can generate during request time than compilation time. It actually defines the XML, which is generated dynamically element body.

Syntax: Here we write XML body tag within this tags

jsp:attribute

This tag is used to define the XML dynamically i.e. the elements can be generated during request time than compilation time It actually defines the attribute of XML which will be generated dynamically.

Syntax: Here we write attribute tag of XML. Example of body and attribute: Action_jsp6.jsp Explanation of the code: Code Line 10: Here we are defining element, which dynamically generated as XML, and its name will be GuruXMLElement Code Line 11-13: Here we are defining an attribute which will XML attribute of the dynamically generated XML. Code Line 14: Here we have body action where we are writing the XML body which will be generated in dynamically XML. When you execute the above code, you get the following output:

Output: Here we get the output from the body tag of generated XML.

jsp:text

It is used to template text in JSP pages. Its body does not contain any other elements, and it contains only text and EL expressions.

Syntax: Here template text refers to only template text (which can be any generic text which needs to be printed on jsp ) or any EL expression. Example: Action_jsp7.jsp Explanation of the code: Code Line 10: Here we are taking text object to print the template text When you execute the above code, you get the following output

Output: We are getting Guru Template Text, which is placed within text action objects.

jsp:output

It specifies the XML declaration or the DOCTYPE declaration of jsp The XML declaration and DOCTYPE are declared by the output

Syntax: Here, doctype-root-element indicates the root element of XML document in DOCTYPE. Doctype-system indicates doctype which is generated in output and gives system literal Example: Explanation of the code: Code Line 10: Here we are using output action object to generate a DOCTYPE, and internally it will be generated in this format:

There won’t be any output for this as this will be generated internally.