[java] 一、js代碼 [java] $(function(){ $.ajax({ type:'post', url:'${ctx}/dictionary/listChannel.do', data:'', dataType:'json', success:function(json){ for(var i=0; i< json.length;i++){ $("#channel_id").append("<option value='" +json[i].value_Id+"'>" +json[i].value+"</option>"); } }, error:function(){ alert('error'); } }); //選擇渠道信息時候,加載版本信息 [java] $("#channel_id").change(function(){ var channel_id=$("#channel_id").val(); $("#version_id").empty(); if (""!= channel_id) { //查詢版本信息 $.ajax({ type:'post', url:'${ctx}/dictionary/listVersion2.do', data:'Id='+channel_id, dataType:'json', success:function(json){ if(null != json){ $("#version_id").append("<option value=''>---請選擇---</option>"); for(var i=0; i< json.length;i++){ $("#version_id").append("<option value='" +json[i].value_Id+"'>" +json[i].value+"</option>"); } } }, error:function(){ alert('該渠道下沒有版本信息'); } }); }else{ $("#version_id").append("<option value=''>---請選擇---</option>"); } }); }); [java] 二、html頁面關鍵代碼 [java] <td align="left" height="18" bgcolor="#ecf6fa"> <span class="STYLE8">渠道標識:</span> <select id="channel_id" name="packageBean.CHANNEL_ID" class="selectstyle200"> <option value="">---請選擇---</option> </select> </td> <td align="left" height="18" bgcolor="#ecf6fa"> <span class="STYLE8">版本標識:</span> <select id="version_id" name="packageBean.VERSION_ID" class="selectstyle200"> <option value="">---請選擇---</option> </select> </td> [java] 三、struts2 action中的方法package com.ecp.web.dictionary.action; import java.io.PrintWriter; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.alibaba.fastjson.JSON; import com.ecp.web.dictionary.business.DictionaryManager; import com.hzdracomsoft.base.BaseAction; import com.hzdracomsoft.common.LogUtil; import com.hzdracomsoft.javabean.Dictionary; /*** * 獲取字典表信息 * @author ZhuangZi * @version $Id: DictionaryAction.java,v 0.1 2013-1-29 上午10:55:53 ZhuangZi Exp $ */ public class DictionaryAction extends BaseAction{ private static LogUtil log = LogUtil.getInstance(DictionaryAction.class); private DictionaryManager dictionaryManager; private Dictionary dictionary; private List<Dictionary> listDictionary; private String Id; /*** * 獲取渠道信息 * */ public void listChannel(){ String json=""; try{ listDictionary = dictionaryManager.handleListChannel(); json=JSON.toJSONString(listDictionary); HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out; out = response.getWriter(); out.println(json); out.flush(); out.close(); }catch(Exception e){ log.error(e); } } /*** * 獲取版本信息 * */ public void listVersion2(){ String json=""; try{ listDictionary=dictionaryManager.handleListVersion(Id); json=JSON.toJSONString(listDictionary); HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out; out = response.getWriter(); out.println(json); out.flush(); out.close(); }catch(Exception e){ log.error(e); } } /*** * 獲取下載包表信息 * @return */ public void listPackage(){ String json=""; try{ listDictionary=dictionaryManager.handleListPackage(Id); json=JSON.toJSONString(listDictionary); HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out; out = response.getWriter(); out.println(json); out.flush(); out.close(); }catch(Exception e){ log.error(e); } } public Dictionary getDictionary() { return dictionary; } public void setDictionary(Dictionary dictionary) { this.dictionary = dictionary; } public List<Dictionary> getListDictionary() { return listDictionary; } public void setListDictionary(List<Dictionary> listDictionary) { this.listDictionary = listDictionary; } public DictionaryManager getDictionaryManager() { return dictionaryManager; } public void setDictionaryManager(DictionaryManager dictionaryManager) { this.dictionaryManager = dictionaryManager; } public String getId() { return Id; } public void setId(String id) { Id = id; } }