ajax+struts实现级联出问题了

本文介绍了一个关于Struts框架中信息加载的问题,具体涉及到Ajax请求处理和XML响应的问题。作者尝试在用户选择一级目录后通过Ajax获取二级目录信息,并将这些信息以XML格式返回。然而,在处理过程中遇到了错误。
[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; 为什么执行到这句代码就报错了,请提示一下,谢谢
【EI复现】基于深度强化学习的微能源网能量管理与优化策略研究(Python代码实现)内容概要:本文围绕“基于深度强化学习的微能源网能量管理与优化策略”展开研究,重点利用深度Q网络(DQN)等深度强化学习算法对微能源网中的能量调度进行建模与优化,旨在应对可再生能源力波动、负荷变化及运行成本等问题。文中结合Python代码实现,构建了包含光伏、储能、负荷等元素的微能源网模型,通过强化学习智能体动态决策能量分配策略,实现经济性、稳定性和能效的多重优化目标,并可能与其他优化算法进行对比分析以验证有效性。研究属于电力系统与人工智能交叉领域,具有较强的工程应用背景和学术参考价值。; 适合人群:具备一定Python编程基础和机器学习基础知识,从事电力系统、能源互联网、智能优化等相关方向的研究生、科研人员及工程技术人员。; 使用场景及目标:①学习如何将深度强化学习应用于微能源网的能量管理;②掌握DQN等算法在实际能源系统调度中的建模与实现方法;③为相关课题研究或项目开发提供代码参考和技术思路。; 阅读建议:建议读者结合提供的Python代码进行实践操作,理解环境建模、状态空间、动作空间及奖励函数的设计逻辑,同时可扩展学习其他强化学习算法在能源系统中的应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值