你的位置:首页 > Java教程

[Java教程]当选择单位的时候,动态关联出人员信息(菜单联动显示信息)


在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;

      }

   });

}

//后台调用方法

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();

   }