s:action使用方法

来源:互联网 发布:高清网络电视下载apk 编辑:程序博客网 时间:2024/05/26 07:30
 

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

  1. id: 可选属性,作为该Action的引用ID   
  2.   
  3. name:必选属性,指定调用Action   
  4.   
  5. namespace:可选属性,指定该标签调用Action所属namespace   
  6.   
  7. executeResult:可选属性,指定是否将Action的处理结果包含到本页面中.默认值为false,不包含.   
  8.   
  9. ignoreContextParam:可选参数,指定该页面的请求参数是否需要传入调用的Action中,默认值是false,即传入参数.  

这个标签可以用来直接显示数据库,既你点开一个页面,不用其它任何触发动作,就要以直接显示从数据库里查找到的数据。

但是它要有两个页面。

使用例子:

view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
  2. <%@ taglib prefix="s" uri="/struts-tags"%>  
  3.   
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  5.   
  6. <html>  
  7.     <head>  
  8.         <title>显示所有用户</title>  
  9.     </head>  
  10.   
  11.     <body>  
  12.   
  13.         <h2 align="center">  
  14.             <font color="red">浏览用户</font>  
  15.         </h2>  
  16.         <div align="center">  
  17.   
  18.             <table align="center" bacolor="pink" border="1px">  
  19.                 <tr bgcolor="yellow">  
  20.                     <th>  
  21.                         用户编号  
  22.                     </th>  
  23.                     <th>  
  24.                         用户名  
  25.                     </th>  
  26.                     <th>  
  27.                         密码  
  28.                     </th>  
  29.                     <th>  
  30.                         角色  
  31.                     </th>  
  32.                     <th>  
  33.                         操作  
  34.                     </th>  
  35.                 </tr>  
  36.   
  37.                 <s:iterator value="users">  
  38.                     <tr>  
  39.                         <td class="nowrap">  
  40.                             <s:property value="userId" />  
  41.                         </td>  
  42.                         <td class="nowrap">  
  43.                             <s:property value="userName" />  
  44.                         </td>  
  45.                         <td class="nowrap">  
  46.                             <s:property value="userPassword" />  
  47.                         </td>  
  48.                         <td class="nowrap">  
  49.                                
  50.                             <s:property value="userRole" />  
  51.                         </td>  
  52.                         <td class="nowrap">  
  53.                             <s:url action="showusers!update" id="url">  
  54.                                 <s:param name="user.userId" value="userId" />  
  55.                             </s:url>  
  56.                             <a href="<s:property value=" mce_href="<s:property value="#url"></a>">Edit</a>      
  57.                             <s:url action="showusers!DeleteUser" id="url">  
  58.                                 <s:param name="user.userId" value="userId" />  
  59.                             </s:url>  
  60.                             <a href="<s:property value=" mce_href="<s:property value="#url"></a>">Delete</a>  
  61.                         </td>  
  62.                     </tr>  
  63.                 </s:iterator>  
  64.             </table>  
  65.         </div>  
  66.         <div align="center">  
  67.             <s:url id="url" action="showusers" />  
  68.             <a href="<s:property value=" mce_href="<s:property value="#url"></a>">刷新</a>  
  69.         </div>  
  70.         <div align="center">  
  71.             <s:url id="url" action="loginresult!Article" />  
  72.             <a href="<%=request.getContextPath()%>/MyJsp.jsp">显示用户</a>  
  73.         </div>  
  74.     </body>  
  75. </html>  

第二个页面

view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@ taglib prefix="s" uri="/struts-tags"%>  
  3.   
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  5. <html>  
  6.   <head>  
  7.      
  8.     <title>My JSP 'MyJsp.jsp' starting page</title>  
  9.    
  10.   </head>  
  11.     
  12.   <body>  
  13.     This is my JSP page. <br>  
  14.     <s:action name="showusers" executeResult="true"/>  
  15.   </body>  
  16. </html> 

原创粉丝点击