Working with JSP action Tags:
Action tags are a set of some basic tags, such as inserting other page resources, forwarding the request to another page, creating and locating the JavaBeans instances, and setting and retrieving bean properties, in JSP pages. Instead of using Java code, the programmer uses special JSP action tags to either link to a Java Bean set its properties, or get its properties.
These are the most commonly used action tags are :
- include
- forward
- param
- useBean
- setProperty
- getProperty
In this article I described the first three action tags, the next three action tags will be described in the next article.
Describing the Include Tag: The include action tag allows a static or dynamic resource such as HTML or JSP pages, specified by a URL, to be included in the current JSP while processing a request.Include action tag is almost similar to include directive. This include can be static or dynamic. This include file is first compiled and output of this file is inserted with parent file. The following code snippet shows the syntax of the include action :
<jsp: include attributes>
<!--zero or more jsp: param tags-->
</jsp: include>
Difference Between Include Directive and Include action:
Include Directive: The 'include' directive tag inserts the given page and includes content in the generated Servlet page during the translation phase of the JSP life cycle. It is generally used to include files, such as HTML, JSP, XML .txt file, into a JSP page statically. The snippet code use for it is:
<%@ include file= "index.jsp" %>
Include Action: The 'include' action tag is used to include the response generated by executing the specified JSP page or Servlet. Unlike the include directive tag, the include action tag accepts expressions. we can decide the page to be included at runtime, whereas it is not possible with the include directive tag. The snippet code use for it is:
<jsp: include page= "index.jsp">
Describing the Forward Tag: The jsp:forward tag forwards the request to another resource. The resource can be dynamic or static. When we use param tags, it is dynamic forward with having values. Static forward is simple forward without having param tags. Forward is used when we need to jump from one page to another if error occur or if work is completed in parent page. The following code snippet shows the syntax of the forward action:




Join the conversation! Your thoughts help the community grow.