3. JSP Action Tag and Expression Language

 

JSP Actions Tag – Java Server Pages

- The use of Action Tags is for controlling the behavior of the Servlet Engine. Action Tags are used during the processing phase of a request.

- Action Tags allow the dynamic insertion of code into JSP. They start with 'jsp:'.


Directives vs Actions

- Directives are used during translation phase while actions are used during request processing phase.

- Unlike Directives Actions are re-evaluated each time the page is accessed.


List of JSP ACtion Tags :

<jsp:include>

<jsp:forward>

<jsp:param>

<jsp:useBean>

<jsp:setProperty>

<jsp:getProperty>

<jsp:plugin>

<jsp:fallback>

<jsp:body>

<jsp:element>

<jsp:attribute>

<jsp:text>


JSP (JavaServer Pages) action tags are special tags used in JSP to perform specific actions or operations. They provide a way to include external content, control page flow, work with JavaBeans, and more. Let's go through each of the mentioned JSP action tags in detail with examples:


1. <jsp:include>

- The `<jsp:include>` tag is used to include the content of another resource (either a JSP page or a servlet) in the current JSP page.

Example:

<%@ include file="header.jsp" %>


2. <jsp:forward>

- The `<jsp:forward>` tag is used to forward the control to another resource, such as another JSP page or a servlet.

Example:

<jsp:forward page="anotherPage.jsp" />


3. <jsp:param>

- The `<jsp:param>` tag is used within `<jsp:forward>` to pass parameters to the target resource.

Example:


<jsp:forward page="anotherPage.jsp">

  <jsp:param name="paramName" value="paramValue" />

</jsp:forward>


4. <jsp:useBean>

The `<jsp:useBean>` tag is used to instantiate a JavaBean or locate a bean in the page context, session, or application scope.


Example:

<jsp:useBean id="myBean" class="com.example.MyBean" scope="request" />


5. <jsp:setProperty>

- The `<jsp:setProperty>` tag is used to set properties on a JavaBean.

Example:

<jsp:setProperty name="myBean" property="propertyName" value="propertyValue" />


6. <jsp:getProperty>

- The `<jsp:getProperty>` tag is used to retrieve and display the value of a property from a JavaBean.


Example:

<jsp:getProperty name="myBean" property="propertyName" />


7. <jsp:plugin>

- The `<jsp:plugin>` tag is used to generate HTML for browser-specific features.


Example:

<jsp:plugin type="applet" code="MyApplet.class" />


8. <jsp:fallback>

- The `<jsp:fallback>` tag is used within `<jsp:plugin>` to provide fallback content for browsers that do not support the plugin.


Example:

<jsp:plugin type="applet" code="MyApplet.class">

  <jsp:fallback>

    Your browser does not support Java applets.

  </jsp:fallback>

</jsp:plugin>


9. <jsp:body>

- The `<jsp:body>` tag is used within tag libraries to define the body content of a custom tag.


Example:

<my:customTag>

  <jsp:body>

    This is the body content of the custom tag.

  </jsp:body>

</my:customTag>



10. <jsp:element>

- The `<jsp:element>` tag is used within tag libraries to dynamically generate an XML element.


Example:

<jsp:element name="book">

  <jsp:attribute name="title">Java Programming</jsp:attribute>

</jsp:element>


11. <jsp:attribute>

-  The `<jsp:attribute>` tag is used within `<jsp:element>` to define attributes for the dynamically generated XML element.


Example:

<jsp:element name="book">

  <jsp:attribute name="title">Java Programming</jsp:attribute>

  <jsp:attribute name="author">John Doe</jsp:attribute>

</jsp:element>



12. <jsp:text>

- The `<jsp:text>` tag is used to output literal text.


Example:

<jsp:text>

  This is some literal text.

</jsp:text>



JSP Expression Language (EL) –


Expression language (EL) has been introduced in JSP 2.0. The main purpose of it to simplify the process of accessing data from bean properties and from implicit objects. EL includes arithmetic, relational and logical operators too.


Synatx of EL:

${expression}

- whatever present inside braces gets evaluated at runtime and being sent to the output stream.

Comments

Popular posts from this blog

2. JSP Scripting elements & Directives

1. JSP Introduction And Life-Cycle