|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
刚刚打开这篇专题,猛然见到HAL9000发表的《对于大型公司项目平台选择j2ee的几层认识》系列,深受启发。asp.net|菜单|成绩|下拉|显现多级下拉菜单的级连显现成绩。
在这里,我为了完成公司-部门级连显现成绩,我编写了leader_add_competence_dialogquery.jsp,web.xml,SelectCropDepartServlet.java类。
个中注重的是leader_add_competence_dialogquery中的.jspChange_Select()javascript函数中的/selectCropDepart是在web.xml中界说的servlet类。我们在完成使用傍边必要修正的用红字标出。
个中leader_add_competence_dialogquery.jsp代码以下:
<%@pagecontentType="text/html;charset=gbk"language="java"import="java.sql.*"errorPage=""%>
<%@pageimport="pub.*"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>增加向导权限</title>
<linkhref="../CSS/putong.css"type="text/css"rel="stylesheet">
<basetarget="_self">
<METAHTTP-EQUIV="Pragma"CONTENT="no-cache">
<METAHTTP-EQUIV="Cache-Control"CONTENT="no-cache">
<METAHTTP-EQUIV="Expires"CONTENT="0">
</head>
<scriptlanguage="javascript">
varreq;
window.onload=function(){
}
functionChange_Select(){
varzhi=document.getElementById(Corp).value;
varurl="../selectCropDepart?id="+escape(zhi);
//alert(url);
if(window.XMLHttpRequest){
req=newXMLHttpRequest();
}elseif(window.ActiveXObject){
req=newActiveXObject("Microsoft.XMLHTTP");
}
if(req){
req.open("GET",url,true);
req.onreadystatechange=callback;
req.send(null);
}
}
functioncallback(){
if(req.readyState==4){
if(req.status==200){
parseMessage();
//updatetheHTMLDOMbasedonwhetherornotmessageisvalid
}else{
alert("Notabletoretrievedescription"+req.status+req.statusText);
}
}
}
functionparseMessage(){
varxmlDoc=req.responseXML.documentElement;
varxSel=xmlDoc.getElementsByTagName(select);
varselect_root=document.getElementById(Depart);
select_root.options.length=0;
for(vari=0;i<xSel.length;i++)
{
varxValue=xSel[i].childNodes[0].firstChild.nodeValue;
varxText=xSel[i].childNodes[1].firstChild.nodeValue;
varoption=newOption(xText,xValue);
try
{
select_root.add(option);
}
catch(e){
}
}
}
functionAddLeaderCompetence(){
varkey=document.all.HiddenKey.value;document.from1.action="leader_ctl.jsp?Oper=addCompetence&Key="+key;
document.from1.submit();
}
</script>
<body>
<%
StringstrUserID=request.getParameter("Key");
session.setAttribute("EmployUserID",strUserID);
%>
<formname="from1"action="leader_ctl.jsp"method="post">
<tablecellSpacing="0"cellPadding="0"width="100%"bgColor="#bfcae6"border="0"background="../images/subtitle.gif">
<tr>
<tdwidth="99%"height="26"><FONTface="宋体">
<DIValign="left"><FONTface="宋体"color="#ffffff">以后地位:体系办理>>向导设置>>增加向导权限</FONT>
</DIV>
</FONT>
</td>
</tr>
</table>
<inputtype="hidden"name="HiddenKey"value="<%=strUserID%>">
<tablewidth="100%"border="0"cellpadding="2"cellspacing="1"bgcolor="#AABDE0">
<trbgcolor="#FFFFFF">
<tdalign="right">公司:</td>
<td>
<SELECTname="Corp"id="Corp">
<OPTIONvalue="all"selected>一切公司</OPTION></SELECT></td>
</tr>
<trbgcolor="#FFFFFF">
<tdalign="right">部门:</td>
<td><SELECTname="Depart"id="Depart">
<OPTIONvalue="all"selected>一切部门</OPTION></SELECT></td>
</tr>
<trbgcolor="#FFFFFF">
<tdcolspan="2"align="center"><inputtype="button"class="button"style="width:80px"value="保留"><inputtype="button"class="button"value="封闭"style="width:80px"></td>
</tr>
</table>
</form>
</body>
<%
Connconn=newConn();
Stringm1Script="";
//Stringm2Script="";
m1Script=PubClass.BindAllCorpList("document.all.Corp");
//m2Script=PubClass.BindAllDepartList("document.all.Depart",""+session.getAttribute("cropid"));
//sPositionList=conn.bindDropListSel("document.all.PositionName","select*fromsys08_Position","PositionName","PositionID");
%>
<%=m1Script%>
</html>
Web.xml代码以下:
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appversion="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>selectCropDepart</servlet-name>
<servlet-class>pub.SelectCropDepartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>selectCropDepart</servlet-name>
<url-pattern>/selectCropDepart</url-pattern>
</servlet-mapping>
</web-app>
SelectCropDepartServlet.javaServlet类代码以下
/**
*从sys04_Machine表中取数据举行二级下拉菜单(公司,部门)及联系关系的servlet类
*@author邓浩
*/
publicclassSelectCropDepartServletextendsHttpServlet{
publicSelectCropDepartServlet(){
super();
}
publicvoiddestroy(){
super.destroy();}
/**
*ThedoGetmethodoftheservlet.<br>
*
*Thismethodiscalledwhenaformhasitstagvaluemethodequalstoget.
*
*@paramrequesttherequestsendbytheclienttotheserver
*@paramresponsetheresponsesendbytheservertotheclient
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control","no-cache");
StringtargetId=request.getParameter("id").toString();
Stringxml_start="<selects>";
Stringxml_end="</selects>";
Stringxml="";
try{
Connconn=newConn();
DataTabledt=newDataTable();
StringSql="select*fromsys04_Machinewherecropid="+targetId;
////System.out.println("Sql:"+Sql);
xml+="<select><value>all</value><text>一切部门</text></select>";
inti=0;
if(conn.querySql(Sql,dt)){
while(i<dt.getRowCount()){
xml+="<select><value>"+dt.getItemForName(i,"MachID").toString()+"</value><text>"+dt.getItemForName(i,"MachName").toString()+"</text></select>";
i=i+1;
}
}
Stringlast_xml=xml_start+xml+xml_end;
//System.out.println("last_xml:"+last_xml);
//last_xml=newString(last_xml.getBytes("UTF-8"),"GB2312");
response.getWriter().write(last_xml);
}//try
catch(Exceptione){
System.out.print(e.getMessage());
}
}
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{
doGet(request,response);
}
publicvoidinit()throwsServletException{
}
}
其实Java之所以在曾经独步天下,就是因为他的跨平台、安全性,这两方面,效率可不是Java的强项,反而是他最短的一块挡板,虽然net总是用理论证明比.NET快。 |
|