ajax+struts實現級聯出問題了

[color=red]index.jsp[/color]

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:directive.page import="com.xiaopeng.pogo.Info" />
<jsp:directive.page import="com.xiaopeng.dao.InfoDao" />
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
var xmlhttp;
function createXMLHttp(){
if(window.ActiveXObject){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
}

function getLevel2(){
createXMLHttp();
url="info.do?id="+document.forms.form1.select1.value;
alert(url);
xmlhttp.open("get",url,false);
xmlhttp.onreadystatechange=function callback(){
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{

addOption();

}
}
};
xmlhttp.send(null);
}

function addOption(){
createXMLHttp();
alert("ddddd");
var xmlDoc=xmlhttp.responseText;
alert("eeeee");
document.getElementById('select2').innerHTML=xmlDoc;

}
</script>
</head>

<body>
<form action="#" name="form1">
<select name="select1" onchange="getLevel2();">
<option value="0">
請選擇一級目錄
</option>
<%
List<Info> list = InfoDao.getFirst();
for (Info info : list) {
request.setAttribute("info", info);
%>
<option value="${info.id }">
${info.name }
</option>
<%
}
%>
</select>
<select name="select2">
<option value="0">
請選擇二級目錄
</option>
</select>
</form>
<br>
</body>
</html>


[color=red]
action[/color]

/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.xiaopeng.struts.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.xiaopeng.dao.InfoDao;
import com.xiaopeng.pogo.Info;

/**
* MyEclipse Struts
* Creation date: 01-03-2009
*
* XDoclet definition:
* @struts.action validate="true"
* @struts.action-forward name="ok" path="index.jsp"
*/
public class InfoAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String id=request.getParameter("id");
Info info1=InfoDao.getInfo(id);
List<Info> list=(ArrayList<Info>)InfoDao.getNext(info1);
response.setContentType("text/xml;charset=gb2312");
String xml_start="<?xml version=\"1.0\" encoding=\"UTF-8\"?><selects>";
String xml_end="</selects>";
String xml="";
for(Info info : list){
xml+="<option value='"+info.getId()+"'>"+info.getName()+"</option>";
}
String last_xml=xml_start+ xml+ xml_end;
try {
response.getWriter().write(last_xml);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(last_xml);
request.setAttribute("aa", "aa");
return mapping.findForward("ok");
}
}


var xmlDoc=xmlhttp.responseText; 爲什麼執行到這句代碼就報錯了,請提示一下,謝謝
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章