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 王耀
*
* @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());
System.out.print("访问到");
} 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());
}
System.out.print("访问到11");
out.write(jsonString);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java服务端生成json(json服务端)
共30个文件
jar:8个
java:5个
class:5个
4星 · 超过85%的资源 需积分: 38 88 下载量 100 浏览量
2018-03-02
15:33:09
上传
评论 2
收藏 1.35MB RAR 举报
温馨提示
java服务端生成json(json服务端),可以在浏览器上访问获取查看json,已测试通过
资源推荐
资源详情
资源评论
收起资源包目录
生成json的服务端.rar (30个子文件)
Json_Gson_FastJson
.project 1KB
src
com
zml
pojo
Person.java 1KB
utils
JsonTools.java 345B
DataUtil.java 1KB
test
JsonServlet.java 3KB
testjson.java 715B
WebRoot
WEB-INF
classes
com
zml
pojo
Person.class 2KB
utils
DataUtil.class 2KB
JsonTools.class 710B
test
JsonServlet.class 2KB
testjson.class 992B
lib
ezmorph.jar 84KB
json-lib-2.2.2-jdk15.jar 141KB
commons-logging-1.1.1.jar 59KB
commons-lang.jar 203KB
gson-2.2.1.jar 185KB
commons-beanutils-1.7.jar 184KB
commons-collections.jar 558KB
gson-2.2.1-sources.jar 123KB
web.xml 936B
index.jsp 829B
META-INF
MANIFEST.MF 39B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 399B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 513B
.jsdtscope 522B
Readme 335B
.classpath 1KB
共 30 条
- 1
资源评论
- cic_csdn2020-06-15分太高,使用价值不大
- 咚咚锵0082020-01-08用idea 成功搭建起来,运行正常,谢谢
wy313622821
- 粉丝: 4w+
- 资源: 136
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功