|
Function buildselect (STR, Sel ){
Sel. Options. Length = 0;
For (VAR I = 0; I <Str. length; I ++ ){
Sel. Options [SEL. Options. Length] = New Option (STR [I], STR [I])
}
}
Function Test (){
// Alert ("test ");
}
</SCRIPT>
<Body>
<Select name = "state" onchange = "getresult (this. Value)">
<Option value = ""> select </option>
<Option value = "ZJ"> Zhejiang </option>
<Option value = "Zs"> Jiangsu </option>
</SELECT>
<Select id = "city"> </SELECT>
</Body>
</Html>
Ii. Servlet Source program
Package com. Stephen. servlet;
Import java. Io. ioexception;
Import java. Io. printwriter;
Import org. dom4j .*;
Import javax. servlet. servletexception;
Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
/**
* @ AUTHOR STEPHEN
*
* Todo to change the template for this generated type comment go to window-
* Preferences-Java-code style-code templates
*/
Public class selectcityservlet extends httpservlet {
Public selectcityservlet (){
Super ();
}
Public void destroy (){
Super. Destroy ();
}
Public void doget (httpservletrequest request, httpservletresponse response)
Throws servletexception, ioexception {
Response. setcharacterencoding ("utf8 ");
Response. setcontenttype ("text/XML ");
Response. setheader ("cache-control", "No-Cache ");
String state = request. getparameter ("state ");
Document document = incluenthelper. createdocument ();
Element root = Document. addelement ("state ");
Element city = NULL;
If ("ZJ". Equals (State )){
City = root. addelement ("city ");
City. settext ("Hangzhou ");
City = root. addelement ("city ");
City. settext ("Huzhou ");
} Else {
City = root. addelement ("city ");
City. settext ("Nanjing ");
City = root. addelement ("city ");
City. settext ("Suzhou ");
City = root. addelement ("city ");
City. settext ("Yangzhou ");
}
Printwriter out = response. getwriter ();
String S = root. asxml ();
Out. Write (s );
Out. Close ();
}
} |