Servelet 处理Json格式数据

/**
* [Product]
*     ExtJS4Study
* [Copyright]
*     Copyright © 2013 Changweihua All Rights Reserved.
* [FileName]
*     DeleteDept.java
* [History]
*     Version         Date            Author          Content
*     --------------- --------------- --------------- ---------------
*     1.0.0           2013-3-23       Changweihua     最初版本
*/
package net.cmono.servlet.lesson18;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.cmono.biz.DeptManager;
import net.cmono.model.Dept;
import net.cmono.util.JsonHelper;
/**
* <b>Summary: </b>
*      TODO 请在此处简要描述此类所实现的功能。
* <b>Remarks: </b>
*      TODO 请在此处详细描述类的功能、调用方法、注意事项、以及与其它类的关系
*/
public class DeleteDept extends HttpServlet {
/**
* 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 {
request.setCharacterEncoding("utf-8");
String json = request.getParameter("data");
List list = JsonHelper.Json2List(json, Dept.class);
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
DeptManager manager = null;
try {
manager = new DeptManager();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
manager.Delete(list);
out.write("{success: true, msg: '删除成功'}");
out.flush();
out.close();
}
/**
* 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 {
doGet(request, response);
}
}

!

知识共享许可协议
《Servelet 处理Json格式数据》常伟华 创作。
采用 知识共享 署名-相同方式共享 3.0 中国大陆 许可协议进行许可。
相邻依据:发表时间
  • 多说评论
  • 签名
  • 新浪微博
  • 默认评论
  • Tab Header 5

1 条评论 / 点击此处发表评论

Tab Content 5

开发技术


开发平台和工具

sitemap     173.23ms