JSP Action Tags:
JSP provides Standard (Action) Tags for use within the JSP pages. These tags are used to eliminate or remove the scriplet code from JSP page since they are not recommended nowadays. Also its not considered good to put JAVA code inside the JSP page.
Unlike directives like these action tags are used during the request processing phase and not during the translation phase as we have seen. Also they will be evaluated every time a page is refreshed or loaded.
The action tags basically are used to control the flow between pages and to use Java Bean. These tags are also used to transfer control from one parent page to another particular page which has been mentioned in the tags.
Action tags are also used in server side inclusion for using javaBean property methods directly in JSP page.
These action tags prefix with “jsp:” as prefix. We have the below action tags present:
Tag | Decription |
jsp:forward | forward the request to the new page |
jsp:getProperty | get the property from JavaBean instance |
jsp:setProperty | stores data in JavaBeans instance |
jsp:include | includes the run time response of a JSP page |
jsp:useBean | instantiates a JavaBean |
jsp:attribute | defines dynamically defined XML element’s attribute |
jsp:param | adds param to the request |
jsp:body | used within custom tags to supply the body tag |
jsp:text | used to write template text in JSP pages |
jsp:plugin | Generates client browser specific construct that makes object or embed tag for the JAVA applets. |
jsp:fallback | Supplies alternate text if java applet is unavailable for the client. |
jsp:element | defines element dynamically |
Generic elements of an action Tag:
Before getting into each JSP action tags, we have to learn some attributes which are common to all action tags.
- Work done by the attribute:
This attribute defines what action the tag does. Say for example a forward tag will forward the current functioning to the JSP which is defined in that tag. Or a include tag will include the output given in that tag along with the current JSP which is being processed.
- Life span of the attribute (scope):
This attribute defines the scope of the attribute upto how long the attribute can be used. This attribute has the below four values:
- page
- request
- session
- application
We will discuss in detail about these scope attributes in the setBean and getBean tags where we can use the maximum of them.