欢迎转载本站文章欢迎转载,但请注明出处(http://www.javajia.com,Java家) |
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(url){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
if(xmlHttp){
xmlHttp.open("GET",url,false);
xmlHttp.onreadystatechange=function(){setState()};
xmlHttp.send(null);
}
}
function setState(){
var selTexts=document.getElementById("selText");
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
parseMessage();
//alert(xmlHttp.responseText);
//selTexts.innerHTML=xmlHttp.responseText;
}
}
}
function parseMessage()
{
var xmlDoc=xmlHttp.responseXML.documentElement;
var xSel=xmlDoc.getElementsByTagName('select');
var select_root=document.getElementById('selText');
select_root.options.length=0;
for(var i=0;i<xSel.length;i++)
{
var xValue=xSel[i].childNodes[0].firstChild.nodeValue;
var xText=xSel[i].childNodes[1].firstChild.nodeValue;
var option=new Option(xText,xValue);
try{
select_root.add(option);
}catch(e){
}
}
}
function getAttrValue(){
var selvalue=document.forms.select1.options[document.forms.select1.selectedIndex].value;
var url="../../../ProdAttrValueType";
if(selvalue==0){
document.getElementById('defaltId').disabled="";
document.getElementById('select2').disabled="disabled";
}else if(selvalue==1){
document.getElementById('defaltId').disabled="disabled";
document.getElementById('select2').disabled="disabled";
}else if(selvalue==2){
document.getElementById('defaltId').disabled="";
document.getElementById('select2').disabled="";
createXMLHttpRequest(url);
}
}
</script>
public class ProdAttrValueType extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
String xml_start="<selects>";
String xml_end="</selects>";
ServletContext sc=this.getServletContext();
WebApplicationContext wc=WebApplicationContextUtils.getWebApplicationContext(sc);
PrintWriter out = response.getWriter();
IProdOfferAttrDao tt=(IProdOfferAttrDao)wc.getBean("prodAttrDao");
StringBuffer sb=new StringBuffer("");
List list=tt.getAttrValueType();
if(list!=null){
Iterator it=list.iterator();
while(it.hasNext()){
ProdOfferAttrActionForm pf=(ProdOfferAttrActionForm)it.next();
//System.out.println(pf.getAttr_Val_Type());"+pf.getAttr_Val_Type()+"
sb.append("<select><value>111</value><text>"+pf.getAttr_Val_Type()+"</text></select>");
}
}
System.out.print(sb.toString());
//out.print()
out.write(xml_start+sb.toString()+xml_end);
out.flush();
out.close();
}
欢迎转载本站文章欢迎转载,但请注明出处(http://www.javajia.com,Java家) |