Action tag example in struts2 framework
Previous | Home | Next |
Struts2 framework provide an action tag ,this tag used to call action class directly through JSP page. If we write “executeResult” is true then action class call or if we write false then action class not call.<s:action name="" executeResult=""/>
Struts2 framework provide a following an action tag,<s:action name="firstAction" executeResult="true"/>
Directory Structure of <s:action> tag Example in Struts 2.0 Using MyEclipse IDEindex.jsp<%@ taglib uri="/struts-tags" prefix="s"%> <h1>Action tag example in struts2 framework </h1> <ol> <li> First action is executed... <s:action name="firstAction" executeResult="true"/> </li> <li> Second action is executed... <s:action name="firstAction!second" executeResult="true"/> </li> <li> Third action is not executed... By defautlt, executeResult="false". <s:action name="firstAction!third"/> </li> </ol>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.ActionTagAction"> <result name="success">/index.jsp</result> </action> <action name="firstAction" class="org.r4r.ActionTagAction" method="first"> <result name="first">/first.jsp</result> <result name="second">/second.jsp</result> <result name="third">/third.jsp</result> </action> </package> </struts>ActionTagAction.javapackage org.r4r; public class ActionTagAction { public String execute(){ return "success"; } public String first(){ return "first"; } public String second(){ return "second"; } public String third(){ System.out.println("SysOut SysOut SysOut"); return "third"; } }first.jsp<h3>This is first action result</h3>second.jsp<h3>This is second action result</h3>third.jsp<h3>This is third action result</h3>Output
Previous | Home | Next |