日期:2014-05-16  浏览次数:20545 次

DWR实现级联 & JSP页面的查询
Problem:

(1) 利用DWR实现三层级联:函数实现,但是无法将js中的object对象转换为用户自定义的对象VideoCateroy

(2)实现JSP页面的查询操作:如何将JS返回的str用于SQL语句

一、利用DWR实现三层级联

1、预期实现结构分析

七年级

---上学期

-------语文

-------数学

-------英语

---下学期

-------语文

-------数学

-------英语

2、编写Java类:getChildCategoryByParentId(int id)

package com.gslsoft.dao;   
/*通过父类Id查找子类目*/  
    @SuppressWarnings("finally")   
    public List<VideoCategory> getChildCategoryByParentId(int id)   
    {   
        String sql="select * from video_category where  parentId='"+id+"'";   
        List<VideoCategory> list=new ArrayList();   
        VideoCategory Category=null;   
        try{   
            CachedRowSet rs = DBConnection.getResultSet(sql);   
            while(rs.next()) {   
                Category= new VideoCategory();   
                Category.setName(rs.getString("name"));   
                Category.setRemark(rs.getString("remark"));   
                Category.setLevel(rs.getInt("level"));   
                Category.setImage(rs.getString("image"));   
                Category.setCategoryId(rs.getInt("id"));   
                list.add(Category);   
            }   
            rs.close();   
        } catch (java.sql.SQLException e) {   
            Logger.log(Logger.ERROR,   
                    "DataRepository_getVideoFileByCategoryId: with CategoryId=" + id);   
            Logger.log(Logger.ERROR, e.toString());   
        } finally {   
            return list;   
        }   
    }  


本文来自CSDN博客,转载请标明出处:file:///C:/Documents%20and%20Settings/Administrator/桌面/我的文件夹/我下载的学习网页/JSP的那些事儿(4)----DWR实现级联%20%26%20JSP页面的查询%20-%20薛敬明的专栏%20-%20CSDN博客.htm


3、编写WEB-INF/dwr.xml:具体的配置说明在前面一章给出了详细的说明
<?xml version="1.0" encoding="GBK"?>     
<dwr>     
    <allow>       
    <create creator="new" javascript="videocategoryservice">  
      <param name="class" value="com.gslsoft.service.VideoCategoryService" />  
    </create>        
  </allow>    
</dwr> 

4、编写Test.jsp页面
view plaincopy to clipboardprint?
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>  
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>  
<%@ page import="java.util.*" %>  
<%@ page import="com.gslsoft.service.*" %>  
<%@ page import="com.gslsoft.model.*" %>  
<html>  
<head>  
<title>文件上传</title>  
<link rel="stylesheet" href="../../css/x_css1.css" mce_href="css/x_css1.css" type="text/css">  
<mce:script type='text/javascript' src="/app/dwr/interface/videocategoryservice.js" mce_src="app/dwr/interface/videocategoryservice.js"></mce:script>  
<mce:script type='text/javascript' src="/app/dwr/interface/VideoCategory.js" mce_src="app/dwr/interface/VideoCategory.js"></mce:script>  
<mce:script type='text/javascript' src="/app/dwr/engine.js" mce_src="app/dwr/engine.js"></mce:script>  
<mce:script type='text/javascript' src="/app/dwr/util.js" mce_src="app/dwr/util.js"></mce:script>  
<mce:script type='text/javascript'><!--   
//根据年级id获取上下学期   
function queryterm()   
{      
   //var gradeid=$("selectgrade").value;   
   var gradeid=window.document.getElementById("selectgradea").value;      
   //默认不选择      
   if(gradeid==0)   
   {   
     window.document.getElementById("selectterma").options.length=0;   
     window.document.getElementById("selectsubjecta").options.length=0;        
   }   
   else   
   {   
     videocategoryservice.getChildCategoryByParentId(gradeid,termCallBack);        
   }   
}   
  
function termCallBack(data)   
{   
  window.document.getElementById("selectterma").options.length=0;