創建一個 Dynamic Web project 項目:
這個file=>new=>Dynamic Web project
打開WebContent目錄
新建一個Api.jsp文件
<%@page import="org.omg.CORBA.Request"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
out.clear();
String string =request.getParameter("action");
if(string!=null){
if(string.equals("send_pass")){
out.print("{\"status\":1}");
}else if(string.equals("login")){
out.print("{\"status\":1,\"token\":\"adadadad\"}");
}else if(string.equals("upload_contacts")){
out.print("{\"status\":1}");
}else if(string.equals("timeline")){
out.print("{\"status\":1,\"page\":1,\"perpage\":20,\"items\":["+
"{\"msg\":\"haha1\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha2\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha3\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha4\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha5\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha12\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha11\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha10\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha9\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha8\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha7\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha100\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha10000\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"},"+
"{\"msg\":\"haha9\",\"phone_md5\":\"md5xxx\",\"msgid\":\"123456\"}"+
"]}");
}else if(string.equals("get_comment")){
out.print("{\"status\":1,\"page\":1,\"perpage\":20,\"items\":["+
"{\"content\":\"Fuck\",\"phone_md5\":\"md5xxx\"},"+
"{\"content\":\"Fuck1\",\"phone_md5\":\"md5xxx\"},"+
"{\"content\":\"Fuck2\",\"phone_md5\":\"md5xxx\"},"+
"{\"content\":\"Fuck3\",\"phone_md5\":\"md5xxx\"},"+
"{\"content\":\"Fuck4\",\"phone_md5\":\"md5xxx\"}"+
"],\"msgid\":\"123\"}");
}else if(string.equals("pub_comment")){
out.print("{\"status\":1}");
}else if(string.equals("publish")){
out.print("{\"status\":1}");
}
}else{
out.print("請指定action");
}
%>
自己按着開發文檔寫的返回格式,寫完之後啓動項目。
簡單舉幾個例子:大家有問題可以留言討論