最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ajax动态加载json数据并详细解析
时间:2022-06-25 15:47:01 编辑:袖梨 来源:一聚教程网
效果图
jsp代码
servlet代码
//get public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String name = request.getParameter("name"); String age = request.getParameter("age"); if (name == null || name == "") { name = "测试名字admin"; } if (age == null || age == "") { age = "测试年龄100"; } user user = new user(1, name, age); PrintWriter out = response.getWriter(); JSONObject jsonObj = JSONObject.fromObject(user); out.print(jsonObj); out.flush(); out.close(); }
//post public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // response.setContentType("text/html"); request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String name = request.getParameter("name"); if (name == null || name == "") { name = "测试名字admin"; } String age = request.getParameter("age"); if (age == null || age == "") { age = "测试年龄100"; } user user = new user(1, name, age); PrintWriter out = response.getWriter(); JSONObject jsonObj = JSONObject.fromObject(user); out.print(jsonObj); out.flush(); out.close(); }
JS核心代码
相关文章
- 宝可梦大集结新手宝可梦怎么选 新手宝可梦推荐介绍 11-07
- 星露谷物语怎么跨平台联机 11-07
- 《使命召唤:黑色行动6》近战专家成就攻略 11-07
- 《使命召唤:黑色行动6》派对结束成就攻略 11-07
- 《使命召唤:黑色行动6》寻找与毁灭成就攻略 11-07
- 《使命召唤:黑色行动6》破坏性觉醒成就攻略 11-07