JqueryEasyUI动态显示数据后台数据

1.代码介绍:

前台使用jsp,JqueryEasyUI制作前台界面,后台使用Servlet实现逻辑编码

2.代码展示:

2.1结构展示:

注:WebRoot目录下的easyui是自己在网上下载JqueryEasyUI库文件复制进去的,其他的jar包,自己导入,不做赘述。

2.2JqueryEasyUI库文件下载:下载网址:http://www.jeasyui.com/download/index.php

注:划线部分为demo案例,可忽略,将其他除txt之外的文件复制到项目中,若所有文件报错,就改变项目的编码格式,若jquery.min.js报错,则重新下一个jquery的js文件。楼主这里是没有报错的。

2.3jsp代码展示:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP ‘index.jsp‘ starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <script type="text/javascript" src="easyui/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>

  </head>

  <body>
      <table id="mTb"
          class="easyui-datagrid" width="100%"
          url="UserServlet?f=query"
          toolbar="#toolbar" pagination="true"
        rownumbers="true" fitColumns="true" singleSelect="true"
        >
        <thead>
            <tr>
                <th field="id" width="50" data-options="hidden: true">编号</th>
                <th field="name" width="50">姓名</th>
                <th field="pass" width="50">密码</th>
                <th field="sex" width="50">性别</th>
                <th field="age" width="50">年龄</th>
                <th field="xueli" width="50">学历</th>
                <th field="address" width="50">地址</th>
            </tr>
        </thead>
      </table>

  </body>
</html>

2.4Servlet代码展示:

package com.scme.servlet;

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 com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.scme.dao.UserDao;
import com.scme.pojo.Userinfo;

public class UserServlet extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public UserServlet() {
        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 {

        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 {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        UserDao dao = new UserDao();
        String flag = request.getParameter("f");
        if(flag.equals("query")) {
            List<Userinfo> mlist = dao.queryAll();
            out.write(new Gson().toJson(mlist));
        }
        out.flush();
        out.close();
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
        // Put your code here
    }

}

重点代码:

List<Userinfo> mlist = dao.queryAll();

out.write(new Gson().toJson(mlist));

注:queryAll()为查询所有信息的方法,自己创建。

2.3数据库代码

/*
Navicat MySQL Data Transfer

Source Server         : aa
Source Server Version : 50519
Source Host           : localhost:3306
Source Database       : test

Target Server Type    : MYSQL
Target Server Version : 50519
File Encoding         : 65001

Date: 2017-05-10 09:51:58
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  `sex` char(2) NOT NULL,
  `age` int(11) NOT NULL,
  `xueli` varchar(30) NOT NULL,
  `address` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (‘1‘, ‘张三‘, ‘123‘, ‘男‘, ‘12‘, ‘本科‘, ‘湖北十堰‘);
INSERT INTO `user` VALUES (‘2‘, ‘李四‘, ‘123‘, ‘男‘, ‘21‘, ‘专科‘, ‘湖北武汉‘);
INSERT INTO `user` VALUES (‘3‘, ‘韩梅梅‘, ‘111‘, ‘女‘, ‘22‘, ‘本科‘, ‘湖北襄阳‘);
INSERT INTO `user` VALUES (‘4‘, ‘静香‘, ‘123‘, ‘女‘, ‘18‘, ‘本科‘, ‘日本东京‘);
INSERT INTO `user` VALUES (‘5‘, ‘大熊‘, ‘111‘, ‘男‘, ‘18‘, ‘专科‘, ‘日本东京‘);
INSERT INTO `user` VALUES (‘8‘, ‘滕金豹‘, ‘111‘, ‘男‘, ‘21‘, ‘本科‘, ‘浙江温州‘);

3.效果展示

时间: 2024-08-07 00:18:52

JqueryEasyUI动态显示数据后台数据的相关文章

前台通过ajax获取后台数据,PHP如何返回中文数据

现在经常使用Ajax调用后台php获取后台数据,但是PHP返回的数据如果含有中文的话,Ajax会无法识别,那咋整呢,我用的是比较笨的方法,但是实用: echo urldecode(json_encode(array('status'=>'1', 'errMsg'=>urlencode('数据传递错误,请重试')))); return;

Java语言实现通过Ajax抓取后台数据及图片

1.Java语言实现通过Ajax抓取后台数据及图片信息 1.1数据库设计 create table picture( pic_id number not null, pic_name varchar(200)not null, pic_url varchar2(200) not null, pic_descp varchar2(200) not null, pic_price varchar2(200) not null ) insert into picture values(1 ,'小米5s

用ajax获取后台数据,返回json数据,怎么在前台使用?

用ajax获取后台数据,返回json数据,怎么在前台使用呢? 后台 C# code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 if (dataType == "SearchCustomer")                 {                     int ID;                     if (Int32.TryParse(CustomerID, out ID))                     {    

解决表单GET提交后台数据乱码问题

?在页面上提交数据到服务器有两种方式"GET"和"POST",当使用"GET"时,传输的数据是直接拼接在URL后面的.当数据中含有对HTML来说不安全的字符例如中文时,就会被编码,一般采用的是UTF-8编码.这时URL已经被转义成相对安全的字符串.此时再经过ios-8859-1的编码方式转换成二进制的形式跟随请求头一起发送到服务器端. ?到达服务器端时,服务器也对数据进行两次解码,服务器先把数据经过ios-8859-1解码,然后根据服务器默认的编

Asp.Net Mvc后台数据验证自测小Demo

*.这里只做后台数据验证,利用mvc数据验证标记验证数据,并获取错误信息提示后页面中. 1.实现效果如下: 2.model类 People.cs using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; namespace WebTest.Areas.Validation.Models { pub

首席工程师揭秘:LinkedIn大数据后台是如何运作的

原文转自:http://kb.cnblogs.com/page/518558/ 摘要:Jay Kreps是来自LinkedIn的首席工程师,他表示日志几乎在计算机产生的时候就存在,除了可用在分布式计算或者抽象分布式计算模型内部之外,还有广泛的用途.本文中他讲述的日志的原理和通过把日志用做单独服务来实现数据集成.实时数据处理以及分布式系统设计.文章内容非常干货,值得学习. 英文原文:The Log: What every software engineer should know about re

拉取后台数据

---------------------------------------------------------------------------------- /** -- * Created by Administrator on 14-8-16. -- *模拟Ajax把数据从数据库中调用出来/后台执行此代码如下/ -- */ -- var http = require('http');/建立服务器的操作/ -- -- http.createServer(function(request

MVVM架构~knockoutjs系列之扩展ajax验证~验证输入数据是否与后台数据相等

返回目录 在看这篇文章之前,你有必要先看我之前的文章,之前文章是将一个方法以参数的形式传给KO,然后返回一个真假值,去做验证,这类似于面向对象语言里的委托,在JS里我们叫它回调方法,本篇文章与前一文章不同,需要有两个参数,其一是远程方法的签名(JS方法),其二是已知要比较的数据(可能是加密后的密码数据),当用户输入文字后,它将会调用JS方法获取远程数据,以比较原数据与你输入的数据是否匹配. 知识点:以对象作为参数进行传递 ko.validation.js的扩展 //ajax相等验证 kv.rul

ajax请求得到后台数据,前台页面不用拼接 “字符串和HTML表格标签”,使用方便模板然后clone,显示表格

<%@page import="java.util.ArrayList"%><%@page import="java.util.List"%><%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%><%@ taglib uri="htt