Tutorials Logic, IN info@tutorialslogic.com

JSP Actions jsp include, jsp forward, jsp useBean

Include and Forward

JSP standard actions use XML-style tags to include output, forward a request, pass parameters, and interact with JavaBeans. Understand their request-time behavior and prefer controllers plus JSTL/EL for modern application structure.

jsp:include invokes another resource during the current request and inserts its generated response. Because inclusion happens at request time, the included resource can produce dynamic output. The including page keeps control after the include finishes unless the response has failed.

jsp:forward transfers the request to another server resource and ends normal processing of the current page. Request attributes remain available. Forward before committing response output; buffered content may be cleared, but relying on late forwarding makes behavior fragile.

Passing Parameters

jsp:param is nested inside include or forward and adds a request parameter for the target resource. Parameters remain strings and may create multiple values when the original request already used the same name. The target must validate them just like client input.

Use request attributes instead when the controller is passing typed server data to a view. Parameters are best for the narrow compatibility cases where the target expects request parameter semantics.

JavaBean Actions

jsp:useBean locates or creates a JavaBean in page, request, session, or application scope. jsp:setProperty writes bean properties and jsp:getProperty renders them. Automatic property population from request parameters is risky because it hides conversion, validation, and writable-field decisions.

In modern MVC code, construct and validate objects in Java, expose a read-only view model as a request attribute, and render it with EL. Recognize Bean actions in legacy pages, but do not use them to place domain mutation or database access in the view.

Action Selection and Failure Boundaries

Use a static include directive for source fragments that should be combined at translation time, jsp:include for dynamic request-time fragments, a controller forward for rendering, and a redirect for a new client request. The choice affects URL, request attributes, buffering, and whether the target executes independently.

Included resources should not reset status or headers unexpectedly. Keep fragment contracts explicit: required attributes, allowed output, character encoding, and error behavior. Avoid chains of includes and forwards that hide which resource owns the response.

Dynamic Include with a Parameter

Dynamic Include with a Parameter
<main>
        <h1>Account</h1>
        <jsp:include page="/WEB-INF/views/fragments/account-summary.jsp">
          <jsp:param name="mode" value="compact" />
        </jsp:include>
      </main>

Forward to an Error View

Forward to an Error View
<jsp:forward page="/WEB-INF/views/not-found.jsp">
        <jsp:param name="source" value="catalog" />
      </jsp:forward>
  • A Servlet controller is usually a clearer place to choose this forward.
Before you move on

JSP Actions jsp include, jsp forward, jsp useBean Mastery Check

6 checks
  • Choose translation-time or request-time inclusion deliberately.
  • Forward before the response is committed.
  • Validate parameters received by included or forwarded resources.
  • Prefer request attributes for typed view models.
  • Keep Bean population and business mutation out of JSP.
  • Document fragment inputs and output ownership.

JSP Actions Questions Learners Ask

jsp:include executes the target for every request. The directive combines source during JSP translation.

No. It is a server-side transfer using the same request and response. A redirect tells the browser to make a new request.

Next Step
Next Practice

Finish the concept here, then reinforce it with hands-on coding, interview prep, or a tool that matches the topic.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.