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:resource >
< bean:resource > – It is used to load a web application resource and make it available as a bean. Retrieves the value of the specified web application resource and make it available as Input Stream or String depending on the input attribute value.
Example Code for < bean:resource>
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
1.Create a simple jsp page BeanResourceTag.jsp.In this page we specify the particular web application resource by name attribute of this tag and id to make available it as a bean.In this example we load a Sample jsp page and display its content.
<%@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> Struts Bean Resource Tag </title> < head> < body bgcolor="#DDDDDD"> < h1 > bean:resource tag example </h1> < bean:resource id="Samplejsp" name="/Sample.jsp"/> < h3> Content of SampleJsp Page which is loaded as web application resource</h3> < bean:write name="Samplejsp" /> < br> </body> </html>
2.Create any Sample jsp page which will be displayed here we used Sample.jsp page to be loaded.
3.Building and running the application
Output
Access page:http://localhost:8084/beanresource/BeanResourceTag.jsp
also read: