首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

http service 失去post请求对象

2014-05-12 
http service 得到post请求对象得到post object的方式一。序列化数据?public String testPost() throws IOE

http service 得到post请求对象

得到post object的方式

一。序列化数据

?

                public String testPost() throws IOException{System.out.println("----得到POST传递过来的对象——doPost start----");InputStream in = ServletActionContext.getRequest().getInputStream();byte[] bytes = new byte[1024*4];int read = in.read(bytes);System.out.println("read:"+read);JSONObject returnjson = new JSONObject();LoginObj obj = new LoginObj();if( read > 0 ){String str = new String(bytes,0,read);System.out.println(str );try {JSONObject json = new JSONObject(str);obj.getValue(json);TwoDimensionalCodeValidate tdcv = new TimeStampUUIDValidate();System.out.println("validate:"+tdcv.validate(obj.two_dim_code));if(tdcv.validate(obj.two_dim_code)){CacheOperation co = new MemCachedOperation();co.saveData(obj);returnjson.put("ret", 1);}else{returnjson.put("ret", 2);}} catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();}PrintWriter out;ServletOutputStream  ps ;ps = ServletActionContext.getResponse().getOutputStream();//ps.print(returnjson.toString().getBytes("UTF-8")); byte[] out_bytes = returnjson.toString().getBytes("UTF-8");ps.write(out_bytes, 0, out_bytes.length);ps.flush();ps.close();return null;}else{try {returnjson.put("ret", 0);} catch (JSONException e) {e.printStackTrace();}PrintWriter out;out = ServletActionContext.getResponse().getWriter();out.print(returnjson);  return null;}}

热点排行