Struts BEAN Paramter Tag ( < bean:parameter >)

SHARE & COMMENT :

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" %>

- It is used to retrieve the value of the specified request parameter and define the result as a page scope attribute of type String (if multiple is not specified).

Example Code for bean:parameter

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 BeanParamTag.jsp which illustrates the bean:parameter tag by retrieving the request parameter value and displaying as a string to the current page.

<%@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 Param Tag </title>
    < head>
    < body bgcolor="#DDDDDD">
        < h1 > bean:parameter tag example  </h1>
		   < bean:parameter name="parameter1" id="param1"/>
		   < bean:parameter name="parameter2" id="param2" value="Java Struts"/>
            < h3> Parameter 1:</h3> < %=param1%> < br>
            < h3> Parameter 2:</h3> < %=param2% />
		  </body>
</html>

2.Modify index.jsp page which redirects to BeanParamTag.jsp page which retreives the parameter values and displays.

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

< jsp:forward page="BeanParamTag.jsp?parameter1=parameter_value"/>

3.Building and running the application

Output

Access page:http://localhost:8084/beanparam/index.jsp

also read:

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better