Set tag example in struts2.0 framework
Previous | Home | Next |
The struts2.0 framework tag library provide to assign value in scope for example application, session, request, page or action but action scope is the default scope in the struts2.0 framework tag library.<s:set var=" " value=" " />
The struts 2.0 framework provide following set tag,<s:set var="userName" value="name" />
Directory Structure of <s:set> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@ taglib prefix="s" uri="/struts-tags" %> <h1>Set tag example in struts2 framework</h1> <h4>Set tag example using action class</h4> <s:set var="studentName" value="name" /> <s:property value="studentName" /> <h4>Not using action class</h4> <s:set var="collegeName" value="%{'Harlal Institute of Management & technology '}" /> <s:property value="collegeName" />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.StudentAction"> <result name="success">/index.jsp</result> </action> </package> </struts>StudentAction.javapackage org.r4r; public class StudentAction { String name="Mukund Singh"; public String getName() { return name; } public void setName(String name) { this.name = name; } public String execute(){ return "success"; } }Output
Previous | Home | Next |