# JSP Action Tags

The JSP Action Tags are used to perform a some specific action task. There are many JSP action tags. The actions are used during request processing where as directive tags are used for translation phase. For controlling the behavior of the servlet engine, the JSP action tags are used as constructs in XML syntax.By using this action tags, a file can be inserted dynamically. To reuse JAVABean components, forward the request and response to another page, or create HTML for Java module.

Tags Description
Jsp:forward Forwards the request and response to other sources
Jsp:include includes other resources
Jsp:element To define  XML elements at runtime.
Jsp:getproperty Prints the property values of the bean
Jsp:useBean Creates bean object
Jsp:plugin Embeds another resource
Jsp:param Set the parameter values. It is used mostly in forward and include pages.
Jsp:setProperty Sets the property estimations in bean objects.
Jsp:attribute Defines XML elements attributes dynamically.
Jsp:body Defines XML elements body.

## JSP: forward

The functionality forward action tag is to forward the request and response to another resource like html or JSP.
Syntax:

<jsp:forward page=“relativeURL | <%= expression %>” />

//jsp:forwar tag with parameters

<jsp:forward page=“relativeURL | <%= expression %>”>  <jsp:param name=“parametername” value=“parametervalue | <%=expression%>” />

</jsp:forward>

Below is an example to jsp:forward tag.

forwardtag.jsp

<html>
<body>
<h2>this is page,here included another file that is printdate.jsp</h2>

<jsp:forward page="printdate.jsp">
<jsp:param name="name" value="WWW.SPLESSONS.COM" />
</jsp:forward>

</body>
</html>


Hete used JSP forward tag for the printdate.jsp .
printdate.jsp


<html>
<body>

<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>
<%= request.getParameter("name") %>

</body>
</html>


request.getParameter() method is used to get the name from forwardtag.jsp.
Output:

While compiling the code forwardtag.jsp file should be in active mode,output will be as follows with current time followed by parameter name.

## JSP: include

The include action tag is utilized to incorporate the substance of the other asset like JSP, HTML, Servlet.JSP include action tag incorporates the substance at solicitation time so its better for element pages since it is utilized for future changes.
Syntax

<jsp:include page=“relativeURL | <%= expression %>” />

//jsp:include action tag with parameter

<jsp:include page=“relativeURL | <%= expression %>”>

<jsp:param name=“parametername” value=“parametervalue | <%=expression%>” />

</jsp:include>

## JSP: useBean

The useBean action tag is used to instantiate a bean class. When bean object is not created, it instantiates the bean. If bean object is available already, it doesn’t rely on upon the bean extent of the object.
Syntax

<jsp:useBean id= “instanceName” scope= “page | request | session | application” class“packageName.className” type= “packageName.className” beanName=“packageName.className | <%= expression >” >
</jsp:useBean>

Below is an example to usebean action tag.

useBean.jsp

<jsp:useBean id="obj" class="com.Question">

<%
String name = obj.message();
out.println("Enter a name");
(
");
%>

</jsp:useBean>


Question.java

package com;

public class Question
{
public String message(){

String name = "john";

return name;
}
}



Output:

Below is an output with name that was provided in .java file.

## JSP: setProperty

The jsp: setProperty activity tag is utilized to set property estimations in a bean utilizing setter method. The setProperty uses java bean for the development of web application.
Syntax

<jsp:setProperty name=“instanceOfBean” property= “*” |

property=“propertyName” param=“parameterName”  |

property=“propertyName” value=“{ string | <%= expression %>}”

/>

## JSP: getProperty

The jsp: getProperty action tag is utilized to get property values in a bean using getter method. This getProperty is used for web application with java bean.
Syntax

<jsp:getProperty name=“instanceOfBean” property=“propertyName” />

Below is an example to set and get properties.

setgetproperty.html


<form action="process1.jsp" method="post">
Name:<input type="text" name="name">

Email:<input type="text" name="email">

<input type="submit" value="register">
</form>


Here just created three text boxes for Name, Password, Email and submit button.
process1.jsp

<jsp:useBean id="u" class="User"></jsp:useBean>
<jsp:setProperty property="*" name="u"/>

Record:

<jsp:getProperty property="name" name="u"/>

<jsp:getProperty property="email" name="u" />


Here get property on the name, password, email.
User.java

public class User {
//setters and getters
}  

Output

Output will be as follows with three text fields and one register button.

## JSP: plugin

The plugin action is utilized to insert the applet or bean into a JSP page, This tag is used when there is a need of plugin to run a Bean class or applet.
Syntax

<jsp: plugin type = “bean” code = “nameOfClassFile
codebase = “directoryNameOfClassFile”>

</jsp: plugin>

## JSP: element

The element tags are utilized to define XML elements at runtime.
Syntax

<jsp:element name=”xmlElement“></jsp:element>

<jsp:attribute name=”xmlAttribute“></jsp:attribute>

## JSP:text

jsp:text action tag is utilized to write the text template in JSP pages.The body template contains only text and EL expressions.
<jsp: text> Template data </jsp: text>

## Summary

• The jsp:plugin action tag is used to embed applet in the JSP file.
• Action tags to control the flow between the pages.
• jsp:fallback will be used  in jsp:plugin to scan  the message.