ajax异步读取后台传递回的下拉选项的值

jsp中html相关代码


    请选择展会:
   


 *

     


js中相关代码


struts-config.xml中相关配置



java后台代码

package oa.sys016.oagzxxgl.action;


import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import net.sf.json.JSONArray;


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 cn.com.chx.bo.AppBo;
/**
 * 通过ajax加载届次选择下拉列表的选择项
 * @author liu
 *
 */
public class DictsAction extends Action{
private AppBo appBo = null;

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 设置编码
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();


appBo = new AppBo();


try {


// 获取ActionType
String actionType = request.getParameter("actionType");


if (actionType != null && actionType.equals("jieci")) { // 查询届次
String jieciJson = getJieciJson();
out.print(jieciJson);
}


} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
}


return null;
}


private String getJieciJson() {
// 查询届次
List jieciList;
try {
jieciList = appBo.query("SELECT ID AS CODE,ZH_NAME AS NAME FROM ZH_GZ_INFOX");


List> lists = new ArrayList>();


if (jieciList.size() > 0) {
for (int i = 0; i < jieciList.size(); i++) {
Map maps = new HashMap();
maps.put("code",
(String) ((HashMap) jieciList.get(i)).get("CODE"));
maps.put("name",
(String) ((HashMap) jieciList.get(i)).get("NAME"));

lists.add(maps);


}
}
// [{"id":"1","name":"CIMT2015"},{"id":"2","name":"CCMT2016"}] 
JSONArray json = JSONArray.fromObject(lists);


return json.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

你可能感兴趣的:(java,jsp,js)