Android-tomcat 中使用OutputStream传过来数据多两个空格
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String age = request.getParameter("age");
System.out.println("POST");
System.out.println("name="+name);
System.out.println("age="+age);
response.setCharacterEncoding("UTF-8");
if(name.equals("q")&&age.equals("1")){
OutputStream out = response.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write("success");
writer.flush();
writer.close();
}else{
OutputStream out = response.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
writer.write("false");
writer.flush();
writer.close();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我android端接受数据
InputStream in = response.getEntity().getContent();
BufferedReader str = new BufferedReader(
new InputStreamReader(in));
String line = null;
line=str.readLine();
比如"success" 接受来之后,在success左右两边多了俩空格" success "
接收之后使用trim()去除空格呢?