-
大小: 4.79MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-09-20
- 语言: JavaScript
- 标签: ajax servlet mysql jquery
资源简介
用jquery中的.getjson()技术和.ajax技术实现从后台中的mysql数据在前台显示,能够直接在myeclipse运行。
代码片段和文件信息
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.linkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONobject;
import org.json.JSONArray;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class JsonServlet extends HttpServlet {
/**
* The doGet method of the servlet.
*
* 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 {
this.doPost(request response);
}
/**
* The doPost method of the servlet.
*
* 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.setHeader(“Content-Type:text/xml;charset=utf-8“ “Cache-Control:no-cache“);
response.setContentType(“text/html“);
PrintWriter out = response.getWriter();
//System.out.println(“hello world!“);
String driver=“com.mysql.jdbc.Driver“;
String url=“jdbc:mysql://localhost:3306/test“;
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
List al=new ArrayList();
//加载驱动
try{
Class.forName(driver);
conn=DriverManager.getConnection(url“root““root“);
statement=conn.createStatement();
String sql=“select * from users“;
rs=statement.executeQuery(sql);
while(rs.next()){
Users users=new Users();
int Id=rs.getInt(“ID“);
//System.out.println(ID);
users.setId(Id);
String username=rs.getString(“username“);
users.setUsername(username);
String password=rs.getString(“password“);
users.setPassword(password);
al.add(users);
}
Gson gson=new Gson();
// Mapject> liut=new HashMapject>();
// for(int i=0;i // Users users=al.get(i);
// String bjson=gson.toJson(users);
// liut.put(i+““ bjson);
// }
String tjson=gson.toJson(al);
out.print(tjson);
/
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\
文件 1151 2016-04-27 11:36 20160427----AjaxJson数据前后台互动\JAS_1\.classpath
文件 1330 2016-04-27 10:13 20160427----AjaxJson数据前后台互动\JAS_1\.project
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\.settings\
文件 522 2016-04-26 17:26 20160427----AjaxJson数据前后台互动\JAS_1\.settings\.jsdtscope
文件 364 2016-04-26 17:26 20160427----AjaxJson数据前后台互动\JAS_1\.settings\org.eclipse.jdt.core.prefs
文件 564 2016-04-27 11:36 20160427----AjaxJson数据前后台互动\JAS_1\.settings\org.eclipse.wst.common.component
文件 414 2016-04-26 17:26 20160427----AjaxJson数据前后台互动\JAS_1\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2016-04-26 17:26 20160427----AjaxJson数据前后台互动\JAS_1\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2016-04-26 17:26 20160427----AjaxJson数据前后台互动\JAS_1\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\me
文件 39 2016-04-26 17:26 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\me
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\
文件 188671 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\commons-beanutils.jar
文件 575389 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\commons-collections-3.2.1.jar
文件 279781 2016-04-27 13:01 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\commons-httpclient.jar
文件 243016 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\commons-lang.jar
文件 38015 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\commons-logging-1.0.4.jar
文件 77667 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\ezmorph-1.0.1.jar
文件 210856 2016-04-27 10:04 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\gson-2.3.1.jar
文件 159123 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\json-lib-2.4-jdk15.jar
文件 703265 2016-04-27 09:10 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\mysql-connector-java-5.1.6-bin.jar
文件 119888 2013-06-09 13:38 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\org.json.jar
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\servlet\
文件 3580 2016-04-27 14:54 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\servlet\JsonServlet.class
文件 905 2016-04-27 13:01 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\servlet\Users.class
文件 108874 2016-04-27 11:30 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\classes\xom-1.0.jar
目录 0 2016-04-27 14:59 20160427----AjaxJson数据前后台互动\JAS_1\WebRoot\WEB-INF\lib\
............此处省略19个文件信息
- 上一篇:1500个前端开发常用ja
vasc ript特效 - 下一篇:后台管理系统界面设计
相关资源
- servlet+jquery实现的网上书店
- jquery实现购物网站
- Springmvc+mybatis+JSON+jQuery+Ajax无刷新登录
- ssh框架整合增删改查项目源码
- 酒店预定管理系统项目源码.rar
- 基于javaweb实现的登录注册以及音乐播
- 点餐系统---------软件工程课程设计
- SSM整合 部门员工增删改查
- SSH三大框架整合+ajax应用+jquery+json应用
- Springmvc+maven+ajax+jquery+json+mybatis登录增
- SpringMVC+Hibernate
- 教务管理系统(spring+springmvc+mybatis+
-
ja
vasc ript高级程序设计英文版第三 - 人事管理系统(注解 Mybatis+Spring+Spr
- wendu.ajaxhook.min
- 一个简单的论坛-Spring+SpringMVC+MyBatis
- 简单的JQuery+AJAX在线聊天室
- Jquery Ajax动态增删改查
- 传智播客2015年教学视频 +JS+AJAX+JQuer
- Plupload + jquery.plupload.queue 批量上传 和
- jQuery快速教程.jquery中文指导
- 一个页面实现Ajax效果的增删改查-JQ
- jQuery Ajax 登陆和注册页面
- ajaxUtil.js
- 用到jQuery的web2.0技术毕业论文导师要
- jQuery实现的瀑布流效果, 向下滚动即
- 基于jQuery的Ajax聊天室程序
- 基于Maven依赖的SSM AJAX增删改查demo
- jQuery_AJAX 无刷新评论
- AjaxFileUploader
评论
共有 条评论