⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zhsoft.jsp

📁 一个利用javabeanjsp产生联动分布的源代码
💻 JSP
📖 第 1 页 / 共 2 页
字号:
<%@ page contentType="text/html;charset=gb2312" import="zhsoft.dbcon.*,java.util.*" errorPage="error.jsp" %>
<%--
  /*****************************************************/
  /* 文件名: zhsoft.jsp                                */
  /* 功  能: 联动式分页列表框显示                      */
  /* 制作者: 纵横软件制作中心雨亦奇(zhsoft88@sohu.com) */
  /*****************************************************/
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>联动式分页列表框示范页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<style>
.chooserList { width:100%; }
</style>
<script>
/* 存放当前框的原始选项 */
var old_options = new Array();
/* 候选框(Candidate)-->当前框(Current):检查候选框中是否有选中的元素要添加到当前框 */
function check_add()
{
 found=0;
 for (i=0;i<formCandidate.select.length;i++)
 if (formCandidate.select.options[i].selected) { found=1; break; }
 if (found) return true;
 return false;
}
/* 当前框(Current)-->候选框(Candidate):检查当前框中是否有选中的元素要删除 */
function check_del()
{
 found=0;
 for (i=0;i<formCurrent.select.length;i++)
 if (formCurrent.select.options[i].selected) { found=1; break; }
 if (found) return true;
 return false;
}
/* 添加操作 */
function myadd()
{
  if (check_add())
  {
    moveSelected(formCandidate.select,formCurrent.select);
    buttonChanged('add','del');
  }
}
/* 删除操作 */
function mydel()
{
 if (check_del())
 {
    moveSelected(formCurrent.select,formCandidate.select);
    buttonChanged('del','add');
 }
}
/* 克隆一个选项 */
function cloneOption(option) {
  var out = new Option(option.text,option.value);
  out.selected = option.selected;
  out.defaultSelected = option.defaultSelected;
  return out;
}
/* 移动选中的元素 */
function moveSelected(from,to) 
{
  newTo = new Array();
  newFrom = new Array();

  for(i=from.options.length - 1; i >= 0; i--) 
  {
    if (from.options[i].selected) 
	{
      newTo[newTo.length] = cloneOption(from.options[i]);
    }
    else
    {
      newFrom[newFrom.length] = cloneOption(from.options[i]);
    }
  }

  for(i=to.options.length - 1; i >= 0; i--) 
  {
    newTo[newTo.length] = cloneOption(to.options[i]);
    newTo[newTo.length-1].selected = false;
  }

  to.options.length = 0;
  from.options.length = 0;

  for(i=newTo.length - 1; i >=0 ; i--) 
  {
    to.options[to.options.length] = newTo[i];
  }

  for(i=newFrom.length - 1; i >=0 ; i--) 
  {
    from.options[from.options.length] = newFrom[i];
  }
}
/* 非焦点列表框中所有元素选中状态清为未选中 */
function clearSelected(unfocusedElement) 
{
  for(i=0; i<unfocusedElement.options.length; i++) {
    unfocusedElement.options[i].selected=false;
  }
}
/* 改变按钮图标 */
function buttonChanged(b1,b2)
{
  var a1 = document.getElementById(b1);
  var a2 = document.getElementById(b2);
  a1.disabled = true;
  var s1 = a1.src.indexOf("_disabled.gif");
  if (s1==-1)
  {
    s1 = a1.src.indexOf(".gif");
	a1.src = a1.src.substring(0,s1)+"_disabled.gif";
  }
  a2.disabled = false;
  var s2 = a2.src.indexOf("_disabled.gif");
  if (s2!=-1)
  {
    a2.src = a2.src.substring(0,s2)+".gif";
  }
  var ap = document.getElementById("apply");
  if (isChanged())
  {
    ap.disabled = false;
  }
  else
  {
    ap.disabled = true;
  }
}
/* 获取当前新增列表框元素,将value值以逗号分隔 */
function get_added_options()
{
  /* 当前框中新增加的列表框元素 */
  var add_options = new Array();
  var curr_options = formCurrent.select.options;
  /* 取新增加的元素:当前列表框中那些没有在原始列表框中出现的元素 */
  add_options = new Array();
  for (i=0;i<curr_options.length;i++)
  {
    found=0;
    for (j=0;j<old_options.length;j++)
    {
      if (curr_options[i].text==old_options[j].text&&curr_options[i].value==old_options[j].value)
	  {
   	    found=1; break;
	  }
    }
    if (found==0)
    {
      add_options[add_options.length]=curr_options[i];
    }
  }
  /* 生成返回串 */
  var s="";
  if (add_options.length>0)
  {
   for (i=0;i<add_options.length-1;i++)
   {
     s+=add_options[i].value+",";
   }
   s+=add_options[i].value;
  }
  return s;
}
/* 获取当前所删列表框元素,将value值以逗号分隔 */
function get_deleted_options()
{
  /* 获取被删除的元素:原始列表框中那些没有在当前列表框中出现的元素 */
  var curr_options = formCurrent.select.options;
  var del_options = new Array();
  for (i=0;i<old_options.length;i++)
  {
    found=0;
    for (j=0;j<curr_options.length;j++)
    {
      if (old_options[i].text==curr_options[j].text&&old_options[i].value==curr_options[j].value)
	  {
	    found=1;break;
	  }
    }
    if (found==0)
    {
      del_options[del_options.length]=old_options[i];
    }
  }
  var s="";
  if (del_options.length>0)
  {
   for (i=0;i<del_options.length-1;i++)
   {
     s+=del_options[i].value+",";
   }
   s+=del_options[i].value;
  }
  return s;
}
/* 是否有改变 */
function isChanged()
{
  if (get_added_options()==""&&get_deleted_options()=="")
  {
    return false;
  }
  else
  {
    return true;
  }
}
/* 使当前框的改变生效 */
function apply_change()
{
  if (isChanged())
  {
   formAction.added.value=get_added_options();
   formAction.deleted.value=get_deleted_options();
  }
  else
  {
    alert('无变化');
  }
}
/* 翻页时确认数据是否更新 */
function verify(myform)
{
 if (isChanged())
 {
  changeit=confirm("确认改变码?");
  if (changeit)
  {
   myform.action="apply.jsp";
   myform.added.value=get_added_options();
   myform.deleted.value=get_deleted_options();
  }
  return true;
 }
 else
 {
  return true;
 }
}
</script>
<body>
<jsp:useBean id="u" scope="session" class="zhsoft.dbcon.Utilities" />
<jsp:useBean id="group" scope="session" class="zhsoft.dbcon.QueryPage" />
<jsp:useBean id="candidate" scope="session" class="zhsoft.dbcon.QueryPage" />
<jsp:useBean id="current" scope="session" class="zhsoft.dbcon.QueryPage" />
<%
    //列表框容纳的数据行数(亦即数据页每页行数)
    final int LINES_PER_PAGE = 15;
    //列表框显示高度
    final int SELECT_LINES = 15;
    //列表框选项之值所对应的数据库字段名
    final String COLUMN_NAME_OF_VALUE = "ID";
    //列表框选项显示之值所对应的数据库字段名
    final String COLUMN_NAME_OF_LABEL = "NAME";
    //组ID
    String group_id = u.trim(request.getParameter("group_id"));
    //组列表框页号
    int group_pageno = u.atoi(request.getParameter("group_pageno"));
    //候选列表框页号
    int candidate_pageno = u.atoi(request.getParameter("candidate_pageno"));
    //当前列表框页号
    int current_pageno = u.atoi(request.getParameter("current_pageno"));
    //组列表框页数据
    ResultRow[] group_rr = null;
    //候选列表框页数据
    ResultRow[] candidate_rr = null;
    //当前列表框页数据
    ResultRow[] current_rr = null;
    //确认更新标志
    int apply_flag = u.atoi(request.getParameter("apply_flag"));

    //组列表框信息初始化
    if (group_pageno<1||group.isInit()==false) {
        group.init("SELECT * FROM TEST_GROUP",LINES_PER_PAGE);
        group_pageno = 1;
    } else {
        if (group_pageno>group.getTotalPages()) {
            group_pageno = group.getTotalPages();
        }
    }
    //设定默认的组ID
    group_rr = group.getPage(group_pageno);
    boolean found = false;
    for (int i=0;i<group_rr.length;i++) {
        if (group_rr[i].getValue(COLUMN_NAME_OF_VALUE).equals(group_id)) {
            found = true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -