Implementation of JSP page two Drop-down frame linkage, real-time reading of database data

Source: Internet
Author: User
Tags chr end modify sql

In a JSP page to achieve a two-level drop-down box linkage, real-time reading of database data, this method is very useful, only need to modify a small place can be used. The design of the document, Serch.jsp,main.js,bytetostr.js,

First, let's talk about Main.js, which is JavaScript, which takes note of modifying the JSP page name.

The following are the referenced contents:
function Findobject (fname,initvalue) ... {
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("POST", "searchmx.jsp?findobject=" +fname+ "&initvalue=" +initvalue,false);/Note Modify JSP page
Xmlhttp.send ();
document.getElementById (FName). INNERHTML=BYTES2BSTR (Xmlhttp.responsebody); Bytes2bstr function in Bytetostr.js
}

followed by Bytetostr.js, which is VBScript, which does not need to modify any content, and his main function is to read the data conversion string.

Function Bytes2bstr (vIn)
Dim i
Strreturn = ""
For i = 1 to LenB (vIn)
Thischarcode = AscB (MidB (vin,i,1))
If Thischarcode < &h80 Then
Strreturn = Strreturn & Chr (Thischarcode)
Else
Nextcharcode = AscB (MidB (vin,i+1,1))
Strreturn = Strreturn & Chr (CLng (thischarcode) * &h100 + CInt (nextcharcode))
i = i + 1
End If
Next
Bytes2bstr = Strreturn
End Function

Next is the serch.jsp page, only need to modify the div in the ID for the name you want, and then the beginning of the package to replace, has been changed SQL statements can be, there is no understanding can participate in the discussion

The following are the referenced contents:

<%@ page contenttype= "text/html; charset=gb2312 "language=" java "import=" com.sjth.zdsygl.vo.*,com.sjth.zdsygl.biz.*,java.util.*, Com.sjth.zdsygl.jdbc.*,java.sql.resultset "%>//Import the appropriate package
<%
This part of the code is used to execute the query database and return the string
if (Request.getparameter ("Findobject")!=null) ... {
if (Request.getparameter ("Findobject"). Equals ("Hy_dm")) ... {
Dbconnect conn = null;
ResultSet rs = null;
Try ... {
Out.print ("<select name= ' hy_dm ' onchange=" javascript:findobject (' hymx_dm ', this.value) ">");
String sql = "SELECT * from Dm_hy group to left (hy_dm,7)";
conn = new Dbconnect ();
CONN.SETPSTMT (SQL);
rs = conn.executequery (SQL);
while (Rs.next ()) ... {
Out.print ("<option value= '" +rs.getstring ("HY_DM") + "' >" +rs.getstring ("HY_MC") + "</option>");
}
Out.print ("</select>");
}
catch (Exception e) ... {
}
Finally ... {
Try ... {
if (Rs!= null)
Rs.close ();
IF (conn!= null)
Conn.close ();
}
catch (Exception e) ... {
E.printstacktrace ();
}
}
}
if (Request.getparameter ("Findobject"). Equals ("Hymx_dm")) ... {
Dbconnect conn = null;
ResultSet rs = null;
Try ... {
Out.print ("<select name= ' hymx_dm ' >");
String sql = null;
if (Request.getparameter ("InitValue"). Equals ("")) ... {
sql = "SELECT * from Dm_hy";
}
else ... {
sql = "SELECT * from Dm_hy where hy_dm like '" +request.getparameter ("InitValue") + "%";
}
conn = new Dbconnect ();
CONN.SETPSTMT (SQL);
rs = conn.executequery (SQL);
while (Rs.next ()) ... {
Out.print ("<option value= '" +rs.getstring ("HY_DM") + "' >" +rs.getstring ("HY_MC") + "</option>");
}
Out.print ("</select>");
}
catch (Exception e) ... {
}
Finally ... {
Try ... {
if (Rs!= null)
Rs.close ();
IF (conn!= null)
Conn.close ();
}
catch (Exception e) ... {
E.printstacktrace ();
}
}
}
Return
}
%>
<link href= "Css/table.css" type= "Text/css" rel= "stylesheet" >
<script language=vbscript src= "Css/bytetostr.js" ></script>
<script language=javascript src= "css/main.js" ></script>//import two JS files
<body>
<div> Industry:</div>
<div id= "HY_DM" ></div>//used to display the returned string
<div > Affiliated Industry:</div>
<div id= "HYMX_DM" ></div>//used to display the returned string
</body>
<script language= "JavaScript" >
Findobject ("Hy_dm", "");
Findobject ("Hymx_dm", "");//These two are page execution is called
</script>

You are welcome to discuss



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.