Ajax实现动态显示并操作表信息的方法(jquery动态加载js文件)原创

随心笔谈1年前发布 编辑
167 0


public class FenleiServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“utf-8”);
String name=request.getParameter(“name”); //项目分类名称
String flag=request.getParameter(“flag”);
String id=request.getParameter(“id”); //项目分类Id
FenleiService cs=new FenleiService();
JSONObject json=new JSONObject();
if(“all”.equals(flag)) {
List<FenleiBean> list=cs.getAll(); //获取所有的项目分类信息
json.put(“getAll”,list);
response.getWriter().print(json.toJSONString());
}
if(“add”.equals(flag)) { //增加操作。
FenleiBean cb=cs.add(name);
json.put(“aFenlei”,cb);
response.getWriter().print(json.toJSONString());
}
if(“delete”.equals(flag)) { //删除操作
boolean result=cs.delete(id);
System.out.println(flag);
System.out.println(result);
if(result){
json.put(“result”,result);
json.put(“msg”,”删除成功”);
response.getWriter().print(json.toJSONString());
System.out.println(json.toJSONString());
} else {
json.put(“result”,result);
json.put(“msg”,”删除失败”);
response.getWriter().print(json.toJSONString());
}
}
if(“update”.equals(flag)) { //更新信息
System.out.println(flag);
String newname=request.getParameter(“newname”);
System.out.println(“—————update newname”+newname);
boolean result=cs.update(newname);
if(result){
json.put(“result”,result);
json.put(“msg”,”修改成功”);
response.getWriter().print(json.toJSONString());
System.out.println(json.toJSONString());
} else {
json.put(“result”,result);
json.put(“msg”,”修改失败”);
response.getWriter().print(json.toJSONString());
}
}
}
}

© 版权声明

相关文章