Skip to content
Home » Standard actions in jsp

Standard actions in jsp

Below is a clear, structured, and detailed discussion of Standard Actions in JSP, written in the same conceptual and technical style as your previous JSP topics.


Standard Actions in JSP

Introduction

Standard actions in JSP are predefined XML-based tags provided by JSP to perform common tasks at request time. These actions help developers control page behavior, manage JavaBeans, include resources dynamically, and forward requests—without embedding Java code directly in JSP pages.

Standard actions are processed during the request processing phase (runtime), unlike directives which are processed at translation time.


Why Standard Actions Are Used

Standard actions are used to:

  • Reduce Java code in JSP
  • Improve readability and maintainability
  • Support dynamic behavior at runtime
  • Encourage separation of concerns
  • Enable reusable and modular JSP pages

General Syntax of JSP Standard Actions

<jsp:actionName attribute="value" />

or

<jsp:actionName attribute="value">
    body
</jsp:actionName>

Types of Standard Actions in JSP

  1. <jsp:useBean>
  2. <jsp:setProperty>
  3. <jsp:getProperty>
  4. <jsp:include>
  5. <jsp:forward>
  6. <jsp:param>
  7. <jsp:plugin>
  8. <jsp:fallback>

1. <jsp:useBean>

Purpose

Creates or locates a JavaBean and makes it available to the JSP page.

Syntax

<jsp:useBean id="user" class="com.app.UserBean" scope="session" />

Key Points

  • Creates a new bean if not found in the given scope
  • Reuses existing bean if already present
  • Common scopes: page, request, session, application

2. <jsp:setProperty>

Purpose

Sets values to properties of a JavaBean.

Syntax

<jsp:setProperty name="user" property="username" value="admin" />

Automatic Property Population

<jsp:setProperty name="user" property="*" />

Automatically maps request parameters to bean properties with matching names.


3. <jsp:getProperty>

Purpose

Retrieves and displays the value of a JavaBean property.

Syntax

<jsp:getProperty name="user" property="username" />

Key Point

  • Uses getter method internally
  • Output is sent directly to response

4. <jsp:include>

Purpose

Dynamically includes another resource (JSP, servlet, HTML) at request time.

Syntax

<jsp:include page="header.jsp" />

Characteristics

  • Dynamic inclusion
  • Included content can change per request
  • No recompilation required if included file changes

5. <jsp:forward>

Purpose

Forwards the current request to another resource on the server.

Syntax

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

Key Characteristics

  • Control is transferred to another page
  • Browser URL remains unchanged
  • Request and response objects are preserved

6. <jsp:param>

Purpose

Passes parameters to <jsp:include> or <jsp:forward> actions.

Syntax

<jsp:forward page="result.jsp">
    <jsp:param name="status" value="success" />
</jsp:forward>

7. <jsp:plugin>

Purpose

Used to embed Java applets or other plugin-based content into JSP pages.

Syntax

<jsp:plugin type="applet" code="MyApplet.class" width="300" height="200" />

Note

  • Rarely used in modern applications
  • Mostly obsolete due to browser restrictions

8. <jsp:fallback>

Purpose

Specifies alternate content if the plugin cannot be executed.

Syntax

<jsp:plugin ...>
    <jsp:fallback>
        Plugin not supported.
    </jsp:fallback>
</jsp:plugin>

Difference Between <jsp:include> and Include Directive

Feature<jsp:include>Include Directive
TimeRequest timeTranslation time
TypeDynamicStatic
RecompilationNot requiredRequired
FlexibilityHighLow

Advantages of Standard Actions

  • Reduce Java code in JSP
  • Improve modularity
  • Support runtime decision-making
  • Encourage MVC architecture
  • Easy to read and maintain

Limitations of Standard Actions

  • Limited functionality compared to JSTL
  • Less flexible for complex logic
  • Plugin-related actions are outdated

Conclusion

Standard actions in JSP provide a powerful mechanism to perform common operations such as JavaBean management, request forwarding, and dynamic inclusion without writing Java code directly in JSP pages. By using tags like <jsp:useBean>, <jsp:setProperty>, and <jsp:include>, developers can create cleaner, more maintainable, and modular JSP applications while adhering to best practices in Java web development.