<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>kind.html</title>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript">
function refreshModelList(){
var oneName=document.getElementById("kindone").value;
if(oneName==""){
clearlist();
return;
}
var url="kind.do?method=search&&kindid="+oneName;
createXMLHttpRequest();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function handleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
setNames();
}
}
}
function clearlist(){
var models=document.getElementById("kindtwo");
while(models.childNodes.length>0){
models.removeChild(models.childNodes[0]);
}
}
function setNames(){
clearlist();
var models=document.getElementById("kindtwo");
var xmlDoc=xmlHttp.responseXML;
var results=xmlDoc.getElementsByTagName("kind");
var option=null;
for(var i=0;i<results.length;i++){
option=document.createElement("option");
option.appendChild(document.createTextNode(results[i].firstChild.nodeValue));
models.appendChild(option);
}
}
</script>
</head>
<body>
<h2>dynamicLists</h2>
<select id="kindone" onchange="refreshModelList();">
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
<option value="4">d</option>
</select>
<select id="kindtwo">
</select>
</body>
</html>
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.rain.struts.action;
import Java.io.IOException;
import Java.io.PrintWriter;
import Java.util.Iterator;
import Java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.validator.DynaValidatorForm;
import com.rain.bean.KindDao;
/**
* MyEclipse Struts
* Creation date: 09-13-2006
*
* XDoclet definition:
* @struts.action parameter="method"
*/
public class KindAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm kindForm = (DynaValidatorForm)form;
KindDao dao=new KindDao();
int kindid=Integer.parseInt(kindForm.getString("kindid"));
List list=dao.findAllKind(kindid);
Iterator it=list.iterator();
if(it.hasNext()){
PrintWriter out;
try {
response.setContentType("text/xml;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
out = response.getWriter();
out.println("<response>");
while(it.hasNext()){
String name=it.next().toString();
out.println("<kind>"+name+"</kind>");
}
out.println("</response>");
it=null;
out.close();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}else{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
// TODO Auto-generated method stub
return null;
}
}
posted on 2006-09-13 12:45
周锐 阅读(944)
评论(0) 编辑 收藏 所属分类:
Ajax 、
Hibernate 、
Struts