国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Jmaki 集成到 struts 一起使用
Jmaki 集成到 struts 一起使用
Author: bsspirit
Source: http://gocom.primeton.com/blog4324_14478.htm

其實(shí)只要明白,list不是通過UserAction傳到UserList.jsp,而是UserList.jsp再訪問另外的Action去取的就行了。

jmaki 是SUN一直大力推進(jìn)的Ajax框架,利用widget的實(shí)現(xiàn)原理,封裝了dojo,google,yahoo之類ajax庫。使用jmaki的同時(shí),又可以用到許多其他開源庫的,非常好的ajax組件。我在這里演示一下,集成dojo.table的demo.

首先,先要明確怎么樣,才能讓jmaki和struts集成。這兩個(gè)同時(shí)是web前臺(tái)的框架。我們?cè)陂_發(fā)struts的時(shí)候,User.jsp --> UserAction --> UserList.jsp,比如是上面的一個(gè)流程,一般是通過在UserAction里面request.setAttribte("list",list),設(shè)置一個(gè)request屬性,然后UserList.jsp通過request.getAttribute("list")讀取出來,或者直接用struts標(biāo)簽或jstl標(biāo)簽讀取list對(duì)象,然后顯示這個(gè)list的內(nèi)容。

現(xiàn)在我們有了ajax技術(shù),他其實(shí)可以不這樣去傳遞對(duì)象了。還是這樣的流程,User.jsp --> UserAction --> UserList.jsp。這時(shí)我們不用在UserAction設(shè)置屬性,只是用struts控制流程。等打開UserList.jsp的頁面以后,再設(shè)定一個(gè)url,去讀取這個(gè)list的內(nèi)容。比如:<a:ajax name="dojo.table" service="http://localhost:8080/test/ListServlet" />。這個(gè)過程其他和讀二進(jìn)制流的概念差不多。取回來的可能是一個(gè)JSon串,也可能是XML文件。JSON串的方式就叫做Rest,XML方式可以直接調(diào)度Web Services。

其實(shí)只要明白,list不是通過UserAction傳到UserList.jsp,而是UserList.jsp再訪問另外的Action去取的就行了。

下面貼一些代碼,是項(xiàng)目里的,還雜著Xdoclet,spring等等你的其他的框架的東西,有點(diǎn)懶得挑出來了,湊合著看。


流程的Action

  1. package com.dvs.biz.web.action.equipcategory;
  2.  
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5.  
  6. import org.apache.commons.logging.Log;
  7. import org.apache.commons.logging.LogFactory;
  8. import org.apache.struts.action.ActionForm;
  9. import org.apache.struts.action.ActionForward;
  10. import org.apache.struts.action.ActionMapping;
  11.  
  12. import com.dvs.common.web.action.BaseAction;
  13. /**
  14. *
  15. * @struts.action path="/jsp/biz/equipcategory/category"
  16. * type="org.springframework.web.struts.DelegatingActionProxy"
  17. * scope="request"
  18. * parameter="action"
  19. * @struts.action-forward name="list" path="/jsp/biz/equipcategory/CategoryList.jsp" redirect="true"
  20. *
  21. * @spring.bean name="/jsp/biz/equipcategory/category"
  22. *
  23. * @author Conan
  24. *
  25. */
  26. public class CategoryAction extends BaseAction{
  27. private final static Log log = LogFactory.getLog(CategoryAction.class);
  28.  
  29. /**
  30. * http://localhost:8880/DVS/jsp/biz/equipcategory/category.do?action=list
  31. * @param mapping
  32. * @param form
  33. * @param request
  34. * @param response
  35. * @return
  36. * @throws Exception
  37. */
  38. public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  39. log.info("CategoryAction : list");
  40. return mapping.findForward("list");
  41. }
  42. }

轉(zhuǎn)向CategoryList.jsp

  1. <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <%@ include file="../../common/taglibs.jsp"%>
  3.  
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  5. <html:html lang="true">
  6. <head>
  7.       <html:base />
  8.       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9.       <title>設(shè)備信息查詢</title>
  10.       <link rel="stylesheet" type="text/css" href="../../../css/main.css">
  11. </head>
  12. <body>
  13.       <html:errors />
  14.       <h2 align="center">設(shè)備大類查詢</h2>
  15.       <div id="m1" align="center">
  16.             <a:ajax name="dojo.table" service="http://localhost:8880/DVS/jsp/biz/equipcategory/jmaki.do?action=categoryList" />
  17.             <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="table7">
  18.                   <tr>
  19.                         <td width="273" height="30">數(shù)據(jù)共2條,第1頁,共1頁</td>
  20.                         <td width="171">
  21.                               <div align="right">
  22.                                     <a href="#"><img src="../../../pic/qj.gif" width="13" height="13" border="0" align="absmiddle"></a> 
  23.                                     <a href="#"><img src="../../../pic/qj1.gif" width="13" height="13" border="0" align="absmiddle"></a> 
  24.                                     <a href="#"><img src="../../../pic/qj1-1.gif" width="13" height="13" border="0" align="absmiddle"></a> 
  25.                                     <a href="#"><img src="../../../pic/qj-1.gif" width="13" height="13"      border="0" align="absmiddle"></a>
  26.                               </div>
  27.                         </td>
  28.                   </tr>
  29.             </table>
  30.       </div>
  31. </body>
  32. </html:html>

(上面的分頁,還有一些東西,還沒有做完。只是為了演示demo用的)
<a:ajax name="dojo.table" service="http://localhost:8880/DVS/jsp/biz/equipcategory/jmaki.do?action=categoryList" />
jsp頁面,通過鏈接再去啟動(dòng)table.

TableAction,這里是提供JSON串的類。

  1. package com.dvs.biz.web.action.ajax;
  2.  
  3. import java.io.PrintWriter;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10.  
  11. import org.apache.commons.logging.Log;
  12. import org.apache.commons.logging.LogFactory;
  13. import org.apache.struts.action.ActionForm;
  14. import org.apache.struts.action.ActionForward;
  15. import org.apache.struts.action.ActionMapping;
  16. import org.json.JSONArray;
  17. import org.json.JSONObject;
  18.  
  19. import com.dvs.biz.model.equipcategory.CategoryDTO;
  20. import com.dvs.biz.model.equipcategory.CategorySubcategoryDTO;
  21. import com.dvs.biz.model.equipgroup.EquipFatherGroupDTO;
  22. import com.dvs.biz.service.equipcategory.EquipCategoryMamtService;
  23. import com.dvs.biz.service.equipcategory.EquipSubcategoryMamtService;
  24. import com.dvs.biz.service.equipgroup.EquipGroupMamtService;
  25. import com.dvs.common.web.action.BaseAction;
  26.  
  27. /**
  28. * @struts.action path="/jsp/biz/equipcategory/jmaki"
  29. * type="org.springframework.web.struts.DelegatingActionProxy"
  30. * scope="request" parameter="action"
  31. *
  32. *
  33. * @spring.bean name="/jsp/biz/equipcategory/jmaki"
  34. * @spring.property name="equipCategoryMamtService" ref="equipCategoryMamtService"
  35. * @author Conan
  36. *
  37. */
  38. public class DojoTableAction extends BaseAction {
  39. private final static Log log = LogFactory.getLog(DojoTableAction.class);
  40.  
  41. private EquipCategoryMamtService equipCategoryMamtService;
  42.  
  43. /**
  44. * http://localhost:8880/DVS/jsp/biz/equipcategory/jmaki.do?action=categoryList
  45. *
  46. * @param mapping
  47. * @param form
  48. * @param request
  49. * @param response
  50. * @return
  51. * @throws Exception
  52. */
  53. public ActionForward categoryList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
  54. log.info("JMakiAction : CategoryList");
  55. List<CategoryDTO> list = equipCategoryMamtService.queryEquipCategory();
  56. PrintWriter out = response.getWriter();
  57. String str = categoryTable(list);
  58. log.info("Json :" + str);
  59. out.print(str);
  60. out.flush();
  61. out.close();
  62. return null;
  63. }
  64.  
  65. @SuppressWarnings("unchecked")
  66. private String categoryTable(List<CategoryDTO> list) {
  67. JSONArray row = new JSONArray();
  68. JSONArray rows = new JSONArray();
  69.  
  70. Map map = new HashMap();
  71. map.put("code", "設(shè)備大類代碼");
  72. map.put("categoryname", "設(shè)備大類名稱");
  73. map.put("description", "設(shè)備大類描述");
  74. map.put("standard", "分類標(biāo)準(zhǔn)");
  75. map.put("detail", "詳情");
  76.  
  77. // input columns
  78. JSONObject columns = DojoTableCommon.setColumns(map);
  79.  
  80. for (CategoryDTO dto : list) {
  81. row.put(dto.getCode());
  82. row.put(dto.getCategoryname());
  83. row.put(dto.getDescription());
  84. row.put(dto.getCode());
  85. row.put("<a href="#">詳情</a>");
  86.  
  87. rows.put(row);
  88. }
  89.  
  90. // input columns,rows
  91. JSONObject table = DojoTableCommon.setTable(columns, rows);
  92. return table.toString();
  93. }
  94.  
  95. public void setEquipCategoryMamtService(EquipCategoryMamtService equipCategoryMamtService) {
  96. this.equipCategoryMamtService = equipCategoryMamtService;
  97. }
  98.  
  99. }

CategoryAction轉(zhuǎn)發(fā)請(qǐng)求給CategoryList.jsp

CategoryList.jsp從DojoTableAction中取回JSON組成table

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Struts2中實(shí)現(xiàn)自定義分頁標(biāo)簽
在Liferay Portal Professional里實(shí)現(xiàn)一個(gè)使用SOAP的portlet
struts原理與實(shí)踐(2)
Struts文件上傳
基于Struts的AJAX
Struts2教程
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服