includetagaction.java
package com.h3.common.action; import com.opensymphony.xwork2.actionsupport; public class includetagaction extends actionsupport{ public string execute() throws exception { return success; } }
include.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> </head> <body> <h1>struts2 <s:include>标签示例</h1> <s:include value="/pages/h3.jsp"></s:include> </body> </html>
h3.jsp
<html> <head> </head> <body> </div><h2>message from h3.jsp</h2> </body> </html>
<?xml version="1.0" encoding="utf-8" ?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devmode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="includetagaction" class="com.h3.common.action.includetagaction" > <result name="success">pages/include.jsp</result> </action> </package> </struts>
http://localhost:8080/struts2includetag/includetagaction.action
在浏览器中访问上面网址,结果输出如下:
代码下载 - http://pan.baidu.com/s/1i3iv1rr