资源简介

java搭建本地服务器,android客户端访问 详细步骤在这里 http://blog.csdn.net/qq_31939617/article/details/79415895

资源截图

代码片段和文件信息

package abc;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.linkedHashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONobject;

public class Test extends HttpServlet {

public void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {

Mapject> map = new linkedHashMapject>();
map.put(“code“ “200“);
map.put(“msg“ ““);

Mapject> map1 = new linkedHashMapject>();
map1.put(“version“ “2.1.0“);
map1.put(“describe“ “1.优化网络加载速度“);
map.put(“data“ map1);

// 无参请求
request.setCharacterEncoding(“UTF-8“);
response.setContentType(“text/html;charset=UTF-8“);
PrintWriter out = response.getWriter();

JSONobject obj = JSONobject.fromobject(map);
out.write(obj.toString());
return;
}

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

}

评论

共有 条评论