Chinaunix首页 | 论坛 | 博客
  • 博客访问: 619659
  • 博文数量: 98
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 1528
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-28 16:20
文章分类

全部博文(98)

文章存档

2011年(1)

2010年(11)

2009年(44)

2008年(42)

我的朋友

分类: Java

2009-03-06 16:28:20

我原先写过1个拿prototype.js写过1个 可惜和htmlarea发生冲突  没办法 只有换了拿DWR写了个

 

先看JSP

Html代码 复制代码
  1. <%@ page language="java" pageEncoding="utf-8"%>  
  2.   
  3. <%@ taglib uri="" prefix="bean" %>  
  4. <%@ taglib uri="" prefix="html" %>  
  5. <%@ taglib uri="" prefix="logic" %>  
  6. <%@ taglib uri="" prefix="tiles" %>  
  7. <%   
  8. String path = request.getContextPath();   
  9. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
  10. %>  
  11.   
  12. >  
  13. <html:html lang="true">  
  14.   <head>  
  15.        
  16.     <title>course.jsptitle>  
  17.   
  18.     <meta http-equiv="pragma" content="no-cache">  
  19.     <meta http-equiv="cache-control" content="no-cache">  
  20.     <meta http-equiv="expires" content="0">       
  21.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  22.     <meta http-equiv="description" content="This is my page">  
  23.       
  24.     <script type="text/javascript" src="<%=basePath%>dwr/util.js">script>  
  25.         <script type="text/javascript" src="<%=basePath%>dwr/engine.js">script>  
  26.         <script type="text/javascript"  
  27.             src="<%=basePath%>dwr/interface/ValidatName.js">script>  
  28.         <script type="text/javascript">  
  29.         function sendRequest(selectValue){   
  30.             ValidatName.ExamQuestionCourse(selectValue,callBackValidatName);   
  31.         }   
  32.            
  33.         function callBackValidatName(data){   
  34.              var json=data;   
  35.              var selectObj = document.getElementById("course_id");   
  36.             selectObj.options.length = 1;              
  37.             for(var i=0; i<json.length; i++){     
  38.                 selectObj[i+1] = new Option(json[i].course_name,json[i].id);                              
  39.             }     
  40.         }   
  41.            
  42.         function sendRequest1(selectValue1){   
  43.             ValidatName.ExamQuestionContent(selectValue1,callBackValidatName1);   
  44.         }   
  45.            
  46.         function callBackValidatName1(data1){   
  47.             var json1 = data1;   
  48.             var selectObj1 = document.getElementById("relation_course_id");   
  49.             selectObj1.options.length = 1;             
  50.             for(var i=0; i<json1.length; i++){                  
  51.                 selectObj1[i+1] = new Option(json1[i].content_title,json1[i].id);               
  52.             }     
  53.         }   
  54.            
  55.            
  56.     script>  
  57.   head>  
  58.      
  59.   <body>  
  60.     <html:form action="/ajax.html?method=prep">  
  61.     <table>  
  62.     <tr>  
  63.     <td width="150" height="26" align="left" class="inputitemname">请选择课件td>  
  64.     <td width="350" align="left" class="tablebody">  
  65.     课程类型:   
  66.         <html:select property="course_type_id" onchange="javascript:sendRequest(this.value);act='';" styleId="id1">  
  67.             <html:option value="0">请选择html:option>  
  68.             <html:options collection="list" property="id" labelProperty="course_type_name"/>  
  69.         html:select><br>  
  70.      课程名称:   
  71.         <html:select property="course_id" onchange="javascript:sendRequest1(this.value);act=''" styleId="course_id" >  
  72.             <html:option value="0">请选择html:option>  
  73.         html:select><br>  
  74.         课程内容:   
  75.         <html:select property="relation_course_id" styleId="relation_course_id">  
  76.             <html:option value="0">请选择html:option>  
  77.         html:select>  
  78.     td>  
  79.   tr>  
  80. html:form>  
  81.     table>  
  82.   body>  
  83. html:html>  

 因为是拿struts写的action就不写出来了 里边就是去顶级数据

在看配置

dwr.xml

Java代码 复制代码
  1. "1.0" encoding="UTF-8"?>   
  2. dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "dwr/dwr20.dtd">   
  3. <dwr>   
  4.        
  5.         "ValidatName" creator="new">   
  6.             "class" value="com.hcwy.service.DwrService">   
  7.            
  8.         "bean" match="com.hcwy.bean.TrainingCourse">    
  9.                 "include" value="id,course_name" />    
  10.             
  11.         "bean" match="com.hcwy.bean.TrainingContent">    
  12.                 "include" value="id,content_title" />    
  13.             
  14.            
  15.        
  16. dwr>  

 

呵呵因为第1次写DWR 所以里边转数据我原先以为要用JSON 结果他里边自动给你转好了 只用写下配置就行了

 

最后看下SERVICE

Java代码 复制代码
  1. package com.hcwy.service;   
  2.   
  3. import java.util.ArrayList;   
  4. import java.util.HashMap;   
  5.   
  6. import org.json.JSONArray;   
  7. import org.json.JSONObject;   
  8.   
  9. import com.hcwy.bean.TrainingContent;   
  10. import com.hcwy.bean.TrainingCourse;   
  11. import com.hcwy.dao.DAO;   
  12.   
  13. public class DwrService {   
  14.   
  15.     public ArrayList ExamQuestionCourse(String id){   
  16.         DAO dao=new DAO();   
  17.         ArrayList list=dao.viewCourse(id);   
  18. //      JSONArray jsonArray = new JSONArray();   
  19. //      for(int i = 0; i < list.size(); i++ ){   
  20. //          TrainingCourse cc = (TrainingCourse)list.get(i);   
  21. //          HashMap map=cc.toHashMap();   
  22. //          JSONObject jsonObject = new JSONObject(map);   
  23. //          jsonArray.add(jsonObject);   
  24. //      }   
  25.         dao.close();   
  26.         return list;   
  27.     }   
  28.        
  29.     public ArrayList ExamQuestionContent(String id){   
  30.         DAO dao=new DAO();   
  31.         ArrayList list=dao.viewContent(id);   
  32. //      JSONArray jsonArray = new JSONArray();   
  33. //      for(int i = 0; i < list.size(); i++ ){   
  34. //          TrainingContent cc=(TrainingContent)list.get(i);   
  35. //          HashMap map=cc.toHashMap();   
  36. //          JSONObject jsonObject = new JSONObject(map);   
  37. //          jsonArray.add(jsonObject);   
  38. //      }   
  39.         dao.close();   
  40.         return list;   
  41.     }   
  42.        
  43. }  

  DAO里就是通过ID取数据 DAO也不想要了

 

呵呵老规矩DEMO项目 如果要的朋友 留下油箱我发给你门

阅读(800) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-06-19 10:16:35

xiaog101@163.com给我一个,谢谢了

chinaunix网友2009-05-30 21:48:39

lzy_695@sina.com,发给我一下,谢了