解释下:我是想通过隐患类型ID级联查询隐患对象和隐患内容(选择隐患类型的select 动态的显示想对应的隐患对象和隐患内容)
先看下代码吧
jsp页面
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ include file="/common/header.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script language="javascript" src="/WebApp/js/validation/prototype.js"
type=""></script>
<head>
<script type="text/javascript">
getTroubleContentByTypeId = function(){
   var troubleTypeId = $("hiddTrouble.troubleTypeId").value;
var actionUrl = 'hiddTroubleAction_getTroubleContentByTypeId.jspx?troubleTypeId='+troubleTypeId+"&session="+ Math.random();
var myAjax = new Ajax.Updater(
        'contentTd', //TODO: 更新的页面元素
        actionUrl, // 请求的URL
        {
            method: 'get',
            evalScripts: true
        }
);
}

getTroubleObjectByTypeId = function(){
   var troubleTypeId = $("hiddTrouble.troubleTypeId").value;
var actionUrl = 'hiddTroubleAction_getTroubleObjectByTypeId.jspx?troubleTypeId='+troubleTypeId+"&session="+ Math.random();
var myAjax = new Ajax.Updater(
        'objectTd', //TODO: 更新的页面元素
        actionUrl, // 请求的URL
        {
            method: 'get',
            evalScripts: true
        }
);
}
</script>
</head>
<!-- 隐患类型列表 -->
<body onload="getTroubleObjectByTypeId(),getTroubleContentByTypeId()">
     <s:select key="隐患类型"
cssStyle="width:250;" name="troubleTypeId"
id="troubleTypeId" required="true"
list="%{#request.troubleTypeList}"
onchange="getTroubleObject(),getTroubleContent()" />
<!-- 隐患对象列表 -->
     <tr class="trwhite">
<td class="tdulleft">
  隐患对象:
</td>
<td class="tdulright" id="objectTd">
<select id="hiddTrouble.objId" name="hiddTrouble.objId"
style="width: 220;">
<option></option>
</select>
</td>
     </tr>

<!-- 隐患内容列表 -->
     <tr class="trwhite">
<td class="tdulleft">
隐患内容:
</td>
         <td class="tdulright" id="contentTd">
<select id="hiddTrouble.contentId" name="hiddTrouble.contentId"
style="width: 220;">
<option></option>
</select>
</td>
     </tr>
</body>在看下struts2配置文件
....
<action name="hiddTroubleAction_*" method="{1}"
class="hiddTroubleAction"></action>..........
在看下java代码action类
/**
 * 通过隐患类型tid级联查询隐患对象
 * @throws Exception
 */
public String getTroubleObjectByTypeId() throws Exception {
List<Map> hiddTroubleObjects = hiddTroubleManager.getTroubleObjectByTypeId(troubleTypeId);
StringBuffer sb = new StringBuffer();
if (hiddTroubleObjects.size() > 0) {
sb.append("<select id='hiddTrouble.objId' name='hiddTrouble.objId' style='width:220;'>");
for (int i = 0; i < hiddTroubleObjects.size(); i++) {
String troubleObj = ((Map) hiddTroubleObjects.get(i)).get("trouble_obj") + "";
String tid = ((Map) hiddTroubleObjects.get(i)).get("tid") + "";
sb.append("<option value='" + tid + "'>" + troubleObj + "</option>");
}
sb.append("</select>");
}
logger.info(sb.toString());
super.outPrint(sb.toString(), false);
return null;
} /**
 * 通过隐患类型tid级联查询隐患对象内容
 * @throws Exception
 */
public String getTroubleContentByTypeId() throws Exception {
List<Map> hiddTroubleContents = hiddTroubleManager.getTroubleContentByTypeId(troubleTypeId);
StringBuffer sb = new StringBuffer();
if (hiddTroubleContents.size() > 0) {
sb.append("<select id='hiddTrouble.contentId' name='hiddTrouble.contentId' style='width:220;'>");
for (int i = 0; i < hiddTroubleContents.size(); i++) {
String troubleCon = ((Map) hiddTroubleContents.get(i)).get("trouble_content") + "";
String tid = ((Map) hiddTroubleContents.get(i)).get("tid") + "";
sb.append("<option value='" + tid + "'>" + troubleCon + "</option>");
}
sb.append("</select>");
}
logger.info(sb.toString());
super.outPrint(sb.toString(), false);
return null;
}
输出到页面的效果是这样的隐患内容和隐患对象的2个select都放到一起了,原因是这明明是2次请求 但是action作为一次请求来处理,我打印response的对象地址都一样?为什么会这样?