在jsp页面中使用onchange属性调用下面的方法:
在script中写入:
function fromid(){ var from_id = $("#from_id").val(); var addurl = "&from_id="+from_id; $.ajax({ url:<select:link page="/YYrequireplan.do?method=fromid"/>+addurl, type:"get", dataType:"json", success:function(html){ document.getElementById("link_man").value = html[0].linkman; document.getElementById("link_tel").value = html[0].tel; document.getElementById("fax").value = html[0].fax; } }); }
//后台action中调用方法
public void fromid(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception{ String from_id = request.getParameter("from_id"); SqlRuturn ret; List list = null; try { ret = Executer.getInstance().ExecSeletSQL("select trim(linkman) as linkman,trim(tel) as tel,trim(fax1) as fax from LO_SUPPLIERFACTORY where factoryid="+from_id); list = ret.getResultSet(); } catch (DbException e) { e.printStackTrace(); } JSONArray jsonarray = JSONArray.fromObject(list); PrintWriter out = response.getWriter(); out.print(jsonarray.toString()); out.close(); }