android和jsp servlet的通信 http协议

客服端的接收代码

public void refresh(){ String timu,a,b,c,d,tishi; int daan,netId; String httpUrl = "http://192.168.20.65:8080/MobielService/servlet/GetExam?par=request-get"; HttpGet request = new HttpGet(httpUrl); HttpClient httpClient = new DefaultHttpClient(); try { HttpResponse response; response = httpClient.execute(request); String str[] = new String[400]; if(response.getStatusLine().getStatusCode()==HttpStatus.SC_OK){ InputStream is= response.getEntity().getContent(); DataInputStream dataStream = new DataInputStream(is); int lenth = dataStream.readInt(); for(int i=0;i<lenth;i++){ timu=dataStream.readUTF(); a=dataStream.readUTF(); b=dataStream.readUTF(); c=dataStream.readUTF(); d=dataStream.readUTF(); daan=Integer.parseInt(dataStream.readUTF()); tishi=dataStream.readUTF(); netId=Integer.parseInt(dataStream.readUTF()); } } } catch (IOException e) { e.printStackTrace(); } }

服务端的发送代码

public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/octet-stream"); getExamGroup(request,response,1); } public void getExamGroup(HttpServletRequest request, HttpServletResponse response,int bianhao ) throws IOException{ OutputStream os = response.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); File read=new File("E://MyEclipse//exam.txt"); BufferedReader br=new BufferedReader(new FileReader(read)); String line = null; dos.writeInt(32); while((line = br.readLine())!=null){ dos.writeUTF(line); } os.close(); dos.close(); }

你可能感兴趣的:(jsp,android,String,servlet,File,null)