随笔 - 59  文章 - 70  trackbacks - 0
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(5)

随笔分类

随笔档案

搜索

  •  

积分与排名

  • 积分 - 172978
  • 排名 - 338

最新评论

阅读排行榜

评论排行榜

public ActionForward getOrganinfo_ajax(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String level2OrganId = request.getParameter( " level2OrganId " );
System.out.print(level2OrganId);
IDReportLogic dreportLogic = (IDReportLogic)SpringFactory.getBeanFactory().getBean( " dreportLogic " );

response.setContentType( " text/xml;charset=UTF-8 " );
response.setHeader( " Cache-control " , " no-cache " );

try {

String orgLevel = request.getParameter( " orgLevel " );
String orgId = request.getParameter( " orgId " );



/**/ /*
以下为前台当中接受到的xml结构。

StringBuffer sb = new StringBuffer();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
String str="<select><kkk><value>11111</value><text>北京</text></kkk>";
String str2="<kkk><value>3333</value><text>上海</text></kkk></select>";
sb.append(str);
sb.append(str2); */

PrintWriter out = response.getWriter();
out.write(str);
out.flush();
return null ;
} catch (Exception e) {
// TODO 自动生成 catch 块
request.setAttribute( " info " , " 获取二级机构异常! " );
e.printStackTrace();
return mapping.getInputForward();
}

}





二级机构:


< select name = " secOrganIdSel " id = " secOrganIdSel "
onchange = " selectChangeListener('2',this.options[this.selectedIndex].value); " >
< option value = " -1 " > 请选择机构.. </ option >
</ select >

三级机构:
< select name = " thdOrganIdSel " id = " thdOrganIdSel "
onchange = " selectChangeListener('3',this.options[this.selectedIndex].value); " >
< option value = " -1 " > 请选择机构.. </ option >

</ select >

四级机构:
< select name = " forthOrganIdSel " >
< option value = " -1 " > 请选择机构.. </ option >
</ select >

< script language = " javascript " type = " text/javascript " >
var xmlHttp;

function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject( " Microsoft.XMLHTTP " );
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}

// 查询指定页面
function selectChangeListener(orgLevel,orgId) {

createXMLHttpRequest();

var url = " <%=request.getContextPath()%>/dreportAction.do?method=getOrganinfo_ajax&orgLevel= " + orgLevel + " &orgId= " + orgId;
xmlHttp.open( " get " ,url, true );
if (orgLevel == ' 2 ') {
// 如果是选择默认的第一个,则是清空后面3级机构和4级机构。
var tempSel = document.getElementById( " secOrganIdSel " );
if (tempSel.options[tempSel.selectedIndex].value == - 1 ) {
var tempSel_1 = document.getElementById( " thdOrganIdSel " );
tempSel_1.options.length = 1 ;
var tempSel_2 = document.getElementById( " forthOrganIdSel " );
tempSel_2.options.length = 1 ;
return false ;
}
xmlHttp.onreadystatechange = callback2;
} else if (orgLevel == ' 3 ') {
// 如果三级机构默认的是第一个选项,则清空第4级机构

var tempSel = document.getElementById( " thdOrganIdSel " );
if (tempSel.options[tempSel.selectedIndex].value == - 1 ) {
var tempSel_2 = document.getElementById( " forthOrganIdSel " );
tempSel_2.options.length = 1 ;
return false ;
}
xmlHttp.onreadystatechange = callback3;
}

xmlHttp.send( null );
}

// 返回信息处理,二级机构下拉列表返回结果
function callback2() {
if (xmlHttp.readyState == 4 ) {
if (xmlHttp.status == 200 ) {
var xmlDoc = xmlHttp.responseXML;
changeSel(' 2 ',xmlDoc);
} else {
window.alert( " 您所请求的页面有异常。 " );
}
}
}


// 返回信息处理,三级机构下拉列表返回结果
function callback3() {
if (xmlHttp.readyState == 4 ) {
if (xmlHttp.status == 200 ) {
var xmlDoc = xmlHttp.responseXML;
changeSel(' 3 ',xmlDoc);
} else {
window.alert( " 您所请求的页面有异常。 " );
}
}
}

// 更新机构下拉列表
function changeSel(orgLevel,xmlDoc) {

// var xsel = xmlDoc.getElementsByTagName('kkk');
var xsel = xmlDoc.documentElement.childNodes;

// alert(xsel.length);
if (orgLevel == ' 2 ') {
// 二级机构,3级机构和4级机构需要清空。
var tempSel_1 = document.getElementById( " thdOrganIdSel " );
tempSel_1.options.length = 0 ;
tempSel_1.add( new Option('请选择机构',' - 1 '))
var tempSel_2 = document.getElementById( " forthOrganIdSel " );
tempSel_2.options.length = 0 ;
tempSel_2.add( new Option('请选择机构',' - 1 '))

for ( var i = 0 ; i < xsel.length;i ++ ) {
var xvalue = xsel[i].childNodes[ 0 ].firstChild.nodeValue;
var xtext = xsel[i].childNodes[ 1 ].firstChild.nodeValue;
var option = new Option(xtext,xvalue);
tempSel_1.add(option);
}

} else if (orgLevel == ' 3 ') {
// 三级机构,四级机构需要清空

var tempSel_2 = document.getElementById( " forthOrganIdSel " );
tempSel_2.options.length = 0 ;
tempSel_2.add( new Option('请选择机构',' - 1 '))

for ( var i = 0 ; i < xsel.length;i ++ ) {
var xvalue = xsel[i].childNodes[ 0 ].firstChild.nodeValue;
var xtext = xsel[i].childNodes[ 1 ].firstChild.nodeValue;
var option = new Option(xtext,xvalue);
tempSel_2.add(option);
}

}

}
</ script >
posted on 2008-04-10 10:19 JasonChou 阅读(806) 评论(0)  编辑  收藏 所属分类: j2ee

只有注册用户登录后才能发表评论。


网站导航: