package com.zml.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zml.utils.DataUtil;
import com.zml.utils.JsonTools;
/**
* @author 郑明亮
* @Time:2016年2月2日 下午10:54:26
* @version 1.0
*/
public class JsonServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public JsonServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @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 doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
this.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 {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String jsonString="";
String actionString = request.getParameter("action");
if (actionString.equals("person")) {
jsonString = JsonTools.createJsonString("person",DataUtil.getPerson());
} else if (actionString.equals("persons")) {
jsonString = JsonTools.createJsonString("persons",DataUtil.getPersons());
} else if (actionString.equals("strings")) {
jsonString = JsonTools.createJsonString("strings",DataUtil.getStrings());
} else if (actionString.equals("maps")) {
jsonString = JsonTools.createJsonString("maps",DataUtil.getMaps());
}
out.write(jsonString);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
json解析服务器端源码

共29个文件
jar:8个
java:5个
class:5个


温馨提示
将对象类型,List包裹对象类型,list包裹String类型,list包裹Map类型数据转换成json数据简单示例源码
资源推荐
资源详情
资源评论










收起资源包目录
















































共 29 条
- 1
资源评论

- qq_165484992018-01-28谢谢谢分享zml_20152021-01-20https://mvnrepository.com/artifact/top.wuyongshi/ZmlToolszml_20152018-04-29no problem
- 忠诚2018-01-18很好用的,源代码可以的。我谢谢上传的会员。谢谢!zml_20152021-01-20可以maven中心库中下载或直接项目依赖 https://mvnrepository.com/artifact/top.wuyongshi/ZmlToolszml_20152018-04-29没事儿,技术重在分享
- digitaland2017-12-10不错,谢谢zml_20152018-04-29you are welcome
- baodingwang2017-11-03不错,谢谢分享!

zml_2015
- 粉丝: 446
- 资源: 73
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
