Bean tag example in struts2 framework
Previous | Home | Next |
Struts2 framework provide a bean tag to instantiate class through JSP page using param tag.<s:bean name="" var=""> <s:param name=""></s:param> </s:bean>
The struts2 framework provide following bean tag,<s:bean name="org.r4r.Student" var="studentName"> <s:param name="name">Student name is MUKUND</s:param> </s:bean>
Directory Structure of <s:bean> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@ taglib prefix="s" uri="/struts-tags" %> <h1>Bean tag example in struts2 framework</h1> <s:bean name="org.r4r.Student" var="studentName"> <s:param name="name">Student name is MUKUND</s:param> </s:bean> This message is generated by bean tag : <s:property value="#studentName.name"/>web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>f1</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>f1</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>struts.xml<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="demo" extends="struts-default"> <action name="" class="org.r4r.BeanAction"> <result name="success">/index.jsp</result> </action> </package> </struts>student.javapackage org.r4r; public class Student { String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }BeanAction.javapackage org.r4r; public class BeanAction { public String execute(){ return "success"; } }Output
Previous | Home | Next |