第一步:
保证手机和电脑连接在同一个局域网。
注意:如果上述方法不适用,请关闭防火墙。
第二步:
利用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. <br>
*
* 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请求:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>com.test.womaifclient.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
</web-app>
第三
步:
打开手机的任意浏览器,输入电脑ip:端口/项目名/Login?username=xxxxxxx,打开网址,测试数据。