Android中POST方式发送HTTP请求(三)

2015-08-31 21:23:56 · 作者: · 浏览: 118
throws ServletException if an error occurred


? ? * @throws IOException if an error occurred


? ? */


? ? public void doPost(HttpServletRequest request, HttpServletResponse response)?


? ? ? ? ? ? throws ServletException, IOException {?


? ? ? ? response.setContentType("text/html;charset=utf-8");?


? ? ? ? request.setCharacterEncoding("utf-8");?


? ? ? ? response.setCharacterEncoding("utf-8");?


? ? ? ? PrintWriter out = response.getWriter();?


? ? ? ? String username = request.getParameter("username");? //传过来的内容是:password=123&username=lili


? ? ? ? System.out.println("username:"+username);?


? ? ? ? String pswd = request.getParameter("password");?


? ? ? ? System.out.println("password:"+pswd);?


? ? ? ? if(username.equals("张三")&&pswd.equals("123")){?


? ? ? ? ? ? //表示服务器端返回的结果?


? ? ? ? ? ? out.print("login is success!!!!");?


? ? ? ? }else{?


? ? ? ? ? ? out.print("login is fail!!!");?


? ? ? ? }?


? ? ?


? ? ? ? out.flush();?


? ? ? ? out.close();?


? ? }?


? ? /**


? ? * Initialization of the servlet.


? ? *


? ? * @throws ServletException if an error occurs


? ? */


? ? public void init() throws ServletException {?


? ? ? ? // Put your code here?


? ? }?


}?


服务端代码使用servlet搭建的。。。


这是运行结果:



服务端的:



在服务端接收的内容是:password=123&username=lili? 被它解析啦。