1.Java代码

public void editProduct(HttpServletRequest request,
            HttpServletResponse response, @RequestParam String id)
            throws IOException, JSONException {
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache, must-revalidate");
        response.setHeader("Pragma", "no-cache");
        Map queryMap = new HashMap();
        queryMap.put("productCode", id);
        List productList = productService.selectlistPageProduct(queryMap, 0, 1);
        if (productList.size() > 0) {
            List mapList = new ArrayList();
            mapList=shoptypeService.ibatorselectShopTypemap();
            /*
             * {
             *  productObj : SendMessageUtil.toJson(productList.get(0))
             *  productType:[SendMessageUtil.toJson(productTypeList.get(0)),SendMessageUtil.toJson(productTypeList.get(1)) ]
             * }
             *
             * */
            org.json.JSONObject productObject = new org.json.JSONObject();
            productObject.put("productObj", SendMessageUtil.toJson(productList.get(0)));
            productObject.put("shopTypeArray", SendMessageUtil.toJson(mapList));
            response.getWriter().write(productObject.toString());
                 
        } else {
            response.getWriter().write(Const.FAIL_STRING);
        }
        response.getWriter().flush();
        response.getWriter().close();
    }

2.页面获取

function editProduct(id){
    $.post("editProduct.do?id="+id,
            function(data) {
                if("fail" == data){
                    alert("【请求失败】");
                }else{
                    var obj = jQuery.parseJSON(data);
                    var product=jQuery.parseJSON(obj.productObj);
                    var shoptype=jQuery.parseJSON(obj.shopTypeArray);//获取到商品类型数组
                    var labers = new Array('商品编号:','商品条码:','商品类型:','商品名:','商品描述:','商品单价:');
                    var texts = new Array(6);
                    texts[0] = ''+
                        '';
                    texts[1] = '';
                    var type_text = '