Struts2 Bean Tag Example
Aim:
Bean tag is used to instantiates the bean class and set the value and gets the value.
Procedure:
Step 1:
Create Project name as BeanPro
Step 2:
Create Action class name as BeanTag
package example;
import java.io.Serializable;
public class BeanTag implements Serializable
{
private String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Step 3:
Create success.jsp
< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< title > JSP Page < /title >
< /head >
< body >
< s:bean name="example.BeanTag" id="uid" >
< s:param name="name" > SureshKumar < /s:param >
< s:property value="%{name}"/ >
< /s:bean >
< /body >
< /html >
Step 4:
Made some changes in struts.xml file
< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >
< struts >
< package name="example" namespace="/example" extends="struts-default" >
< action name="actionTag" class="example.actionTag" >
< result name="success" > /example/success.jsp < /result >
< /action >
< /package >
< /struts >
step 5:
Run the success.jsp
Directory structure of this project
No comments:
Post a Comment