Struts BEAN Tag Library
Struts BEAN tag library provides tags which are usefull in accessing beans and their properties as well as defining new beans (based on these accesses) that are accessible to the remainder of the page via scripting variables and page scope attributes. Convenient mechanisms to create new beans based on the value of request cookies, headers, and parameters are also provided.
Syntax to use Struts BEAN tag library
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
< bean:page >
< bean:page > – It is used to retrieve the value from the Page Context of this current page and make it accessible from current page. Name property of this tag must be one of the application, config, request, response, or session.
Example Code for < bean:page>
In this example we do not need the ActionForm bean.
In this example we do not need the Action class.
No need to configure struts-config.xml file
Create a simple jsp page BeanPageTag.jsp which illustrates the < bean:page> tag by id and property attributes.
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-html" %> <%@taglib prefix="bean" uri="http://jakarta.apache.org/struts/tags-bean" %> < html> < head> < title> Bean Page Tag </title> < head> < body bgcolor="#DDDDDD"> < h1 > bean:page tag example </h1> < bean:page id="variable1" property="request"> < bean:page id="variable2" property="application"> < h3> Session:</h3> < bean:write name="variable1" /> < br> < h3> Application:</h3> < bean:write name="variable2" /> </body> </html>
5.Building and running the application
Output
Access page:http://localhost:8084/beanpage/BeanPageTag.jsp
also read: