public ActionForward jsonForTxry(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws ParseException{ LazyValidatorForm txryjcForm=(LazyValidatorForm)form;
int start=(txryjcForm.get("start")==null)?1:(Integer)txryjcForm.get("start"); int size=(txryjcForm.get("limit")==null)?10:(Integer)txryjcForm.get("limit");
String qdwdm=(txryjcForm.get("qdwdm")==null)?"":txryjcForm.get("qdwdm").toString(); String zdwdm=(txryjcForm.get("zdwdm")==null)?"":txryjcForm.get("qdwdm").toString(); String bbrq=(txryjcForm.get("bbrq")==null)?"":txryjcForm.get("qdwdm").toString(); String lx60=(txryjcForm.get("lx60")==null)?"":txryjcForm.get("qdwdm").toString(); String lx55=(txryjcForm.get("lx55")==null)?"":txryjcForm.get("qdwdm").toString(); String lx50=(txryjcForm.get("lx50")==null)?"":txryjcForm.get("qdwdm").toString(); String bdq=(txryjcForm.get("bdq")==null)?"":txryjcForm.get("qdwdm").toString();
String qxbm=UserInfo.getInstance().getQxbm();
Map <Object,Object> map=new HashMap <Object,Object>(); map.put("qdwdm", qdwdm); map.put("zdwdm", zdwdm); map.put("bbrq",new java.sql.Date(new SimpleDateFormat("yyyy/mm/dd").parse(bbrq).getTime())); map.put("lx60", lx60); map.put("lx55", lx55); map.put("lx50", lx50); map.put("bdq", bdq); map.put("qxdm", qxbm);
Page queryPage=txryjc.pagedQuery(GrViewTxryjc.class, map, start / size + 1, size);
JSONObject json=new JSONObject(); try{ json.put("Total", queryPage.getTotalCount()); json.put("Limit", size); JSONArray list=new JSONArray(); List rows=(List)queryPage.getResult(); for(int i=0;i <rows.size();i++){ GrViewTxryjc grViewTxryjc=(GrViewTxryjc)rows.get(i); Map convert=new HashMap(); map.put("jclb", grViewTxryjc.getJclb()); map.put("dwdm", grViewTxryjc.getDwdm()); map.put("dwmc", grViewTxryjc.getDwmc()); map.put("xm", grViewTxryjc.getXm()); map.put("xb", grViewTxryjc.getXb()); map.put("bzhm", grViewTxryjc.getBzhm()); map.put("csrq", grViewTxryjc.getCsrq()); list.put(map); json.put("txryjc", list); } } catch(JSONException e){ e.printStackTrace(); System.out.println("错误:"+e.getMessage()); } this.renderText(response, json.toString()); return null; }
//在父类的类中
protected void renderText(HttpServletResponse response, String text) { render(response,text,"text/plain;charset=UTF-8"); }
protected void render(HttpServletResponse response, String text,String contentType){ try { response.setContentType(contentType); response.getWriter().write(text); } catch (IOException e) { log.error(e.getMessage(), e); } }
这个是手动转的JSON 是struts1.X的写法 2.0也可以这么转,用struts2.0的JSON转换也可以(有时候好像有问题) 要用上面的写法要去下个 JSON的JAR文件 网上有~~
|