[struts]s:action 的使用方法

转自:http://blog.csdn.net/amwihihc/article/details/4122738

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

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

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

但是它要有两个页面。

使用例子:

[xhtml] view plaincopy

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

第二个页面

[xhtml] view plaincopy

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%@ taglib prefix="s" uri="/struts-tags"%>
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  4. <html>
  5. <head>
  6. <title>My JSP 'MyJsp.jsp' starting page</title>
  7. </head>
  8. <body>
  9.     This is my JSP page. <br>
  10. <s:action name="showusers" executeResult="true"/>
  11. </body>
  12. </html>
posted @ 2013-03-24 15:18  wanpp590  阅读(330)  评论(0编辑  收藏  举报