Title, directly on the code, Combat learning.
Copy Code code as follows:
<script type= "Text/javascript" >
function init () {
Makemoduleselect ();
}
Load Template dropdown box options
function Makemoduleselect () {
$.ajax ({
URL: ' indexstatisticsaction_getselect.jsp ',
Data: {page: ' clientindexstatistics.jsp ', Method: ' Get_modtitlecode '},
Success:function (Result) {
$ ("#makemodule"). Append (result);
}
});
}</script>
<body onload= "init ()" >
Dropdown box <select name= "Makemodule" id= "Makemodule" style= ' width:130px ' onchange= ' makemoduleselected ' () ' >
<option>-------</option>
</select></body>
When the above HTML is loaded, because the onload attribute is set in the body tag, its corresponding JavaScript function will run, and finally to function makemoduleselect (), take a look at it:
URL properties, similar to the AJAX jump URL, here I use the same path of the JSP page (indexstatisticsaction_getselect.jsp), the following will be shown;
The Data property, which is taken as the requested parameter, is fetched by the request;
The Success property, which represents the code that will execute after the AJAX request for this jquery is successfully returned, where $ ("#makemodule") refers to the Drop-down box.
The following is the AJAX request for the URL of the JSP, where the deletion of the JDBC-related packages, the introduction of their own, JDBC is not much to say, according to the needs of the business logic code out.
Copy Code code as follows:
<%@ page import= "java.util.*"%>
<%@ page import= "Java.sql.ResultSet"%>
<%@ page import= "Java.io.PrintWriter"%>
<%
String userId = (string) session.getattribute ("UserId");
String method = Request.getparameter (' method ');
String frompage = request.getparameter ("page");
String SQL1 = "Select Modtitlename,modtitlecode from makemodule where UserID = '? userid? ' and modulename_en= '? modulename_e N? ' GROUP by Modtitlename ';
SYSTEM.OUT.PRINTLN ("---getting select_option from:" +frompage+ "----" + new Date ());
Get template Options
if (Method.equals ("Get_modtitlecode")) {
String sql = Sql1.replace ("? userId?", userId);
if (Frompage.equals ("acindexstatistics.jsp")) {
sql = Sql.replace ("Modulename_en?", "Acsta");
}else if (frompage.equals ("apindexstatistics.jsp")) {
sql = Sql.replace ("Modulename_en?", "Apsta");
}else if (frompage.equals ("clientindexstatistics.jsp")) {
sql = Sql.replace ("Modulename_en?", "Terminalsta");
}
SYSTEM.OUT.PRINTLN (SQL);
StringBuffer rsoption = new StringBuffer ();
DB db = new db ();
try {
Db.preparequery ();
ResultSet rs = db.executequery (SQL);
while (Rs!=null && rs.next ()) {
Rsoption.append ("<option value= '" +rs.getstring ("Modtitlecode") + ">" +STRINGOPERATOR.ISO2GB (rs.getString (" Modtitlename ") +" </option> ");
}
Rs.close ();
catch (Exception e) {
E.printstacktrace ();
finally {
Db.endquery ();
}
PrintWriter pout = Response.getwriter ();
Pout.write (Rsoption.tostring ());
Pout.flush ();
Pout.close ();
}
%>
The SQL statement above will take out two values, which are the display and truth values of the Select Drop-down box, and the Set <option> label postback is OK.