Imported package:
<SCRIPT type = 'text/JavaScript 'src = 'njs/jquery-AutoComplete/jquery. autocomplete. js'> </SCRIPT>
<LINK rel = "stylesheet" type = "text/CSS" href = "NJS/jquery-AutoComplete/jquery.autocomplete.css"/>
JSCode:
VaR I = 0;
VaR jtcmnames = ['','', ''];
Function Change (valu ){
// Alert (jtcmnames );
VaR doc_value = valu. value;
If (I = doc_value.length ){
} Else {
I = doc_value.length;
Doc_value = encodeuri (valu. Value ));
Createxmlhttp ();
XMLHTTP. Open ("Post", "autocomplete. do? Input_content = "+ doc_value, false );
XMLHTTP. Send (null );
VaR names = XMLHTTP. responsetext;
Jtcmnames = names. Split ("|"); // After receiving the server-side data, we need to parse the data. The data in JSON format is actually an array.
// Alert (jtcmnames );
$ ("# Column04"). AutoComplete (jtcmnames, {matchcontains: True, AutoFill: false });
XMLHTTP. closed;
}
}
Struts-config.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype Struts-config public "-// Apache Software Foundation // DTD struts configuration 1.1 //" http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
<Struts-config>
<Form-beans>
</Form-beans>
<Action-mappings>
<Action Path = "/AutoComplete" parameter = "#" type = "com. sitech. ismp. iimp. common. action. autocompleteaction "Scope =" request "Validate =" false ">
<Forward name = "default" Path = "/common/getalldealedlist. jsp"/>
</Action>
</Action-mappings>
</Struts-config>
Action:
Public void AutoComplete (actionmapping mapping,
Actionform, httpservletrequest request,
Httpservletresponse response) throws exception {
String query_value = java.net. urldecoder. decode (request. getparameter ("input_content"), "UTF-8"); // transcode the data. This must be the case because the data is also transferred on the JSP page to maintain consistency.
Tblsys_loginmsg user = (tblsys_loginmsg) request. getsession ()
. Getattribute (tblsys_loginmsg.session_key); // only obtains the current user
String login_id = NULL;
If (user! = NULL )&&! User. Equals ("")){
Login_id = user. getlogin_id ();
}
Request. setcharacterencoding ("UTF-8 ");
Response. setcontenttype ("text/html ");
Response. setcharacterencoding ("UTF-8 ");
Sys_loginmsgdao autocompletedao = new sys_loginmsgdao ();
If (query_value! = NULL &&! Query_value.trim (). Equals ("")){
List autocompletelist = autocompletedao. findtitleforjsname (query_value, login_id );
If (autocompletelist! = NULL &&! Autocompletelist. isempty ()){
Query_value = ibsmutil. getjsarrayfromlist (autocompletelist, "titile ");
Response. getwriter (). append (ibsmutil. getjsarrayfromlist (autocompletelist, "titile "));
Response. getwriter (). Flush ();
Response. getwriter (). Close ();
}
}
}
The disadvantage of this method is: If you enter the first word, it will not be automatically prompted, only the second input will be prompted, because the first time it is just to assign a value to the variable, the second time, you can read the variables one by one for prompt.