android手机连接电脑myeclipse服务器做联机测试

第一步:

     保证手机和电脑连接在同一个局域网。
     注意:如果上述方法不适用,请关闭防火墙。

第二步:

     利用Myeclipse新建一个web项目,

     我这里写的项目名为WomaifClientTestWeb,

     新建一个Login.java继承自HttpServlet,在doget()方法中调用dopost()。

    在dopost()中写入调试传入的数据和需要返回的数据。

public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
           doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. 
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); String username = request.getParameter("username"); String sign = request.getParameter("sign"); System.out.println("username:"+username); System.out.println("sign:"+sign); PrintWriter out = response.getWriter(); out.print("回传参数成功!"); out.flush(); out.close(); }

        在web.xml中配置好Login请求:


  
    index.jsp
  
  
  
    Login
    com.test.womaifclient.Login
  
  
    Login
    /Login
  
第三 步:

打开手机的任意浏览器,输入电脑ip:端口/项目名/Login?username=xxxxxxx,打开网址,测试数据。



你可能感兴趣的:(测试,myeclipse,android)