s:action标签的使用方法

来源:互联网 发布:微软软件下载 编辑:程序博客网 时间:2024/05/15 23:51

s:action标签的使用方法

使用struts2的action标签时,可以在jsp页面直接调用Action,在调用Action的时候,可以指定Action的name和namespace,如果指定了executeResult参数的属性值为true,那么该标签会把Action的处理结果(即视图资源)包含到本页面中。s:action标签指定属性有:

id:可选属性,作为该Action的应用ID

name:必选属性,指定需要调用的Action名

namespace:可选属性,指定该标签调用Action所属的namespace

executeResult:可选属性,指定是否将Action的处理结果包含到本页面中.默认值为false(不包含)

ignoreContextParam:可选参数,指定该页面的请求参数是否需要传入调用的Action中,默认值是false,即传入参数

 

实例:index.jsp主要代码

 

[html] view plaincopyprint?
  1. <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>  
  2. <%@taglib prefix="s" uri="/struts-tags"%>  
  3. <%  
  4. String path = request.getContextPath();  
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  6. %>  
  7.   
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  9. <html>  
  10.   <head>  
  11.     <base href="<%=basePath%>">  
  12.       
  13.     <title>Struts2 a:action</title>  
  14.   
  15.   </head>  
  16.     
  17.   <body>  
  18.       <div>  
  19.         <s:action name="modle_show" namespace="/webs" executeResult="true">  
  20.              <s:param name="name" value='1'>  
  21.              </s:param>  
  22.         </s:action>   
  23.       </div>  
  24.       
  25.   </body>  
  26. </html>  


test.jsp主要代码

[html] view plaincopyprint?
  1. <%@ page contentType="text/html; charset=UTF-8" language="java"%>  
  2. <%@taglib uri="/struts-tags" prefix="s"%>  
  3. <s:property value="content" escape="false" />  


 

struts.xml的action代码:

[java] view plaincopyprint?
  1. <action name="modle_*" class="modleAction" method="{1}" >  
  2.             <result name="test">/webs/content.jsp</result>  
  3.         </action>  


 

 这样当访问index.jsp时,会在页面上执行modle_show这个aciton,并将最终的结果页面(也就是test.jsp上所有的结果页面)包含在index.jsp中

原创粉丝点击