1webcontent部分

1 修改menu.jsp代码

2 jsp/customer/list.jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>客户列表</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath }/css/Style.css" type=text/css rel=stylesheet>
<LINK href="${pageContext.request.contextPath }/css/Manage.css" type=text/css
rel=stylesheet>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.4.4.min.js"></script>
<SCRIPT language=javascript>
function to_page(page){
if(page){
$("#page").val(page);
}
document.customerForm.submit();
}
$(function(){
$.post(
"${pageContext.request.contextPath}/customer",
{"method":"findAllCustomerList"},
function(data){
/*
* [
* {"cust_id":2,"cust_name":"谷歌有限公司"},
* {"cust_id":6,"cust_name":"张三","cust_source":"阿里巴巴","cust_level":"vip","cust_linkman":"李四","cust_phone":"1234","cust_mobile":"4321"},
* {"cust_id":7,"cust_name":"新浪科技","cust_level":"贵宾","cust_linkman":"李四"},
* {"cust_id":8,"cust_name":"联想公司"},
* {"cust_id":9,"cust_name":"永安会计事务所","cust_source":"国际事务所成员","cust_level":"vip","cust_linkman":"马大强","cust_phone":"789632541","cust_mobile":"123456789"}
* ]
*/
var content="<TR style='FONT-WEIGHT: bold; FONT-STYLE: normal; BACKGROUND-COLOR: #eeeeee; TEXT-DECORATION: none'>"+
"<TD>客户名称</TD>"+
"<TD>客户级别</TD>"+
"<TD>客户来源</TD>"+
"<TD>联系人</TD>"+
"<TD>电话</TD>"+
"<TD>手机</TD>"+
"<TD>操作</TD>"+
"</TR>"; for(var i=0;i<data.length;++i){
content+="<TR style='FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none'>"+
"<TD>"+data[i].cust_name+"</TD>"+
"<TD>"+data[i].cust_level+"</TD>"+
"<TD>"+data[i].cust_source+"</TD>"+
"<TD>"+data[i].cust_linkman+"</TD>"+
"<TD>"+data[i].cust_phone+"</TD>"+
"<TD>"+data[i].cust_mobile+"</TD>"+
"<TD>"+
"<a href='${pageContext.request.contextPath }/customerServlet?method=edit&custId=${customer.custId}'>修改</a>"+
"&nbsp;&nbsp;"+
"<a href='${pageContext.request.contextPath }/customerServlet?method=delete&custId=${customer.custId}'>删除</a>"+
"</TD>"+
"</TR>"; }
$("#customerListId").html(content); },
"json"
);
});
</SCRIPT> <META content="MSHTML 6.00.2900.3492" name=GENERATOR>
</HEAD>
<BODY>
<FORM id="customerForm" name="customerForm"
action="${pageContext.request.contextPath }/customerServlet?method=list"
method=post> <TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_019.jpg"
border=0></TD>
<TD width="100%" background="${pageContext.request.contextPath }/images/new_020.jpg"
height=20></TD>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_021.jpg"
border=0></TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15 background=${pageContext.request.contextPath }/images/new_022.jpg><IMG
src="${pageContext.request.contextPath }/images/new_022.jpg" border=0></TD>
<TD vAlign=top width="100%" bgColor=#ffffff>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
<TR>
<TD class=manageHead>当前位置:客户管理 &gt; 客户列表</TD>
</TR>
<TR>
<TD height=2></TD>
</TR>
</TABLE>
<TABLE borderColor=#cccccc cellSpacing=0 cellPadding=0
width="100%" align=center border=0>
<TBODY>
<TR>
<TD height=25>
<TABLE cellSpacing=0 cellPadding=2 border=0>
<TBODY>
<TR>
<TD>客户名称:</TD>
<TD><INPUT class=textbox id=sChannel2
style="WIDTH: 80px" maxLength=50 name="custName"></TD> <TD><INPUT class=button id=sButton2 type=submit
value=" 筛选 " name=sButton2></TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR> <TR>
<TD>
<TABLE id=grid
style="BORDER-TOP-WIDTH: 0px; FONT-WEIGHT: normal; BORDER-LEFT-WIDTH: 0px; BORDER-LEFT-COLOR: #cccccc; BORDER-BOTTOM-WIDTH: 0px; BORDER-BOTTOM-COLOR: #cccccc; WIDTH: 100%; BORDER-TOP-COLOR: #cccccc; FONT-STYLE: normal; BACKGROUND-COLOR: #cccccc; BORDER-RIGHT-WIDTH: 0px; TEXT-DECORATION: none; BORDER-RIGHT-COLOR: #cccccc"
cellSpacing=1 cellPadding=2 rules=all border=0>
<TBODY id="customerListId">
<!-- <TR
style="FONT-WEIGHT: bold; FONT-STYLE: normal; BACKGROUND-COLOR: #eeeeee; TEXT-DECORATION: none">
<TD>客户名称</TD>
<TD>客户级别</TD>
<TD>客户来源</TD>
<TD>联系人</TD>
<TD>电话</TD>
<TD>手机</TD>
<TD>操作</TD>
</TR> --> <%-- <TR style="FONT-WEIGHT: normal; FONT-STYLE: normal; BACKGROUND-COLOR: white; TEXT-DECORATION: none">
<TD>${customer.custName }</TD>
<TD>${customer.custLevel }</TD>
<TD>${customer.custSource }</TD>
<TD>${customer.custLinkman }</TD>
<TD>${customer.custPhone }</TD>
<TD>${customer.custMobile }</TD>
<TD>
<a href="${pageContext.request.contextPath }/customerServlet?method=edit&custId=${customer.custId}">修改</a>
&nbsp;&nbsp;
<a href="${pageContext.request.contextPath }/customerServlet?method=delete&custId=${customer.custId}">删除</a>
</TD>
</TR> --%> </TBODY>
</TABLE>
</TD>
</TR> <TR>
<TD><SPAN id=pagelink>
<DIV
style="LINE-HEIGHT: 20px; HEIGHT: 20px; TEXT-ALIGN: right">
共[<B>${total}</B>]条记录,[<B>${totalPage}</B>]页
,每页显示
<select name="pageSize"> <option value="15" <c:if test="${pageSize==1 }">selected</c:if>>1</option>
<option value="30" <c:if test="${pageSize==30 }">selected</c:if>>30</option>
</select>

[<A href="javascript:to_page(${page-1})">前一页</A>]
<B>${page}</B>
[<A href="javascript:to_page(${page+1})">后一页</A>]

<input type="text" size="3" id="page" name="page" />
页 <input type="button" value="Go" onclick="to_page()"/>
</DIV>
</SPAN></TD>
</TR>
</TBODY>
</TABLE>
</TD>
<TD width=15 background="${pageContext.request.contextPath }/images/new_023.jpg"><IMG
src="${pageContext.request.contextPath }/images/new_023.jpg" border=0></TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_024.jpg"
border=0></TD>
<TD align=middle width="100%"
background="${pageContext.request.contextPath }/images/new_025.jpg" height=15></TD>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_026.jpg"
border=0></TD>
</TR>
</TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>

2 web层

1 CustomerServlet->findAllCustomerList方法

//2获取客户列表findAllCustomerList
public void findAllCustomerList(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//解决乱码问题通过GenericEncodingFilter
List<Customer> customerList = service.findAllCustomerList(); //转换成json
Gson gson = new Gson();
String json = gson.toJson(customerList); //System.out.println(json);
/*
* [
* {"cust_id":2,"cust_name":"谷歌有限公司"},
* {"cust_id":6,"cust_name":"张三","cust_source":"阿里巴巴","cust_level":"vip","cust_linkman":"李四","cust_phone":"1234","cust_mobile":"4321"},
* {"cust_id":7,"cust_name":"新浪科技","cust_level":"贵宾","cust_linkman":"李四"},
* {"cust_id":8,"cust_name":"联想公司"},
* {"cust_id":9,"cust_name":"永安会计事务所","cust_source":"国际事务所成员","cust_level":"vip","cust_linkman":"马大强","cust_phone":"789632541","cust_mobile":"123456789"}
* ]
*/
//回写
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write(json); }

3 service层

1 CustomerServie接口

package www.test.service;

import java.util.List;

import www.test.domain.Customer;

public interface CustomerService {

    //保存客户
void save(Customer customer); //获取客户列表
List<Customer> findAllCustomerList(); }

2 CustomerServiceImpl实现类

@Override
//获取客户列表,这里实际上不需要事务控制,只是为了练习而已
public List<Customer> findAllCustomerList() {
//获得session
Session session = HibernateUtils.getCurrentSession();
//控制事务
Transaction transaction = session.beginTransaction();
List<Customer> customerList =null;
try {
//调用dao层获取客户列表
customerList = dao.findAllCustomerList();
} catch (Exception e) {
e.printStackTrace();
transaction.rollback();
}finally{
transaction.commit();
}

4 dao层

1 CustomerDao接口

package www.test.dao;

import java.util.List;

import www.test.domain.Customer;

public interface CustomerDao {

    //保存客户
void save(Customer customer); //获取客户列表
List<Customer> findAllCustomerList(); }

2 CustomerDaoImpl实现类

@Override
//获取客户列表
public List<Customer> findAllCustomerList() {
//获得session
Session session = HibernateUtils.getCurrentSession();
//创建执行者对象
Criteria criteria = session.createCriteria(Customer.class);
//执行操作
List<Customer> list = criteria.list(); return list;
}

5 再次复习记忆

1 BaseServlet

package www.test.web.servlet;

import java.io.IOException;
import java.lang.reflect.Method; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("all")
public class BaseServlet extends HttpServlet { @Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//解决乱码问题
resp.setContentType("text/html;charset=UTF-8"); try {
// 1 获得请求的method方法
String methodName = req.getParameter("method");
// 2获得当前被访问的对象的字节码对象
Class clazz = this.getClass(); //ProductServlet.class --- UserServlet.class
// 3 获取当前字节码对象中指定的方法
Method method = clazz.getMethod(methodName,HttpServletRequest.class,HttpServletResponse.class);
// 4 执行相应的方法
method.invoke(this,req,resp);
} catch (Exception e) {
e.printStackTrace();
} } }

2 BeanFactory工具类

package www.test.utils;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
@SuppressWarnings("all")
public class BeanFactory { public static Object getBean(String id){
//生成对象--根据清单生产--配置文件--将每一个bean对象的生产细节配置到配置文件中 //使用dom4j的xml解析技术 导入两个jar包
// dom4j-1.6.1.jar 和 jaxen-1.1-beta-6.jar try {
// 1 创建解析器
SAXReader reader = new SAXReader();
// 2 解析文档--bean.xml 在src下面
String path = BeanFactory.class.getClassLoader().getResource("bean.xml").getPath();
//读取
Document doc = reader.read(path); // 3 获得元素--参数是xpath规则
Element element = (Element) doc.selectSingleNode("//bean[@id='"+id+"']");
//<bean id="adminService" class="www.test.service.impl.AdminServiceImpl"></bean>
String className = element.attributeValue("class");
//www.test.service.impl.AdminServiceImpl //使用反射创建对象
Class clazz = Class.forName(className);
Object object = clazz.getDeclaredConstructor().newInstance(); return object; } catch (Exception e) { e.printStackTrace();
} return null;
}
}

案例42-使用ajax获取crm中的客户列表的更多相关文章

  1. Jquery的ajax获取action中的返回值

    js部分: function check() {  $.ajax({     type : "POST",     url : "myCloudWantseeListHD ...

  2. ajax获取数据库中数据

    xhr=new XMLHttpRequest(); var url="要获取数据的地方"; xhr.open('post',url,true); POST请求头(get就不用写这个 ...

  3. 获取一个Assembly中的命名空间列表

    通过System.Reflection.Assembly类中提供的方法和属性不能直接获取组件中的命名空间列表.但有方法可以直接获得Assembly中的所有类型,我们便可以通过获取的类型来得到命名空间名 ...

  4. JavaScript 在函数中使用Ajax获取的值作为函数的返回值

    解决:JavaScript 在函数中使用Ajax获取的值作为函数的返回值,结果无法获取到返回值 原因:ajax默认使用异步方式,要将异步改为同步方式 案例:通过区域ID,获取该区域下所有的学校 var ...

  5. 在Dynamis CRM中打造一键保存关闭刷新案例的功能

    关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复172或者20151114可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 我们知道在Dynamics CR ...

  6. vue 中使用 AJAX获取数据的方法

    在VUE开发时,数据可以使用jquery和vue-resource来获取数据.在获取数据时,一定需要给一个数据初始值. 看下例: <script type="text/javascri ...

  7. 通过Jquery中Ajax获取json文件数据

    1. JSON(JavaScript Object Notation): javaScript对象表示法: 是存储和交换文本信息的语法,比xml更小,更快,更易解析. 2. JSON基本书写格式 : ...

  8. Java基础知识强化之IO流笔记47:IO流练习之 随机获取文本文件中的姓名案例

    1.  随机获取文本文件中的姓名案例     需求:我有一个文本文件中存储了几个名称,请大家写一个程序实现随机获取一个人的名字.     分析:           A:  把文本文件中的数据存储到集 ...

  9. 笔记-返回到前一个页面时显示前一个页面中ajax获取的数据

    笔记第一部分:http://www.cnblogs.com/zczhangcui/p/6869219.html 在第一部分遇到的问题是,用ajax获取了一系列列表信息后,拼接好html后插入到了原有页 ...

随机推荐

  1. ElasticSearch 笔记(一)

    一.Elasticsearch 印象 分布式.全文检索.数据分析. 二.为什么不用传统关系型数据库,如 MySQL,做搜索 举个反例.假设有以下数据库表 t_game: id   name 1 唐僧取 ...

  2. Robot Framework 使用总结

    最近项目上使用了RF快速实现了一些验收测试的自动化case,感觉不错,很好用,下面就记录一下使用RF实现自动化的过程. 什么是RF? RF是一种测试框架,帮助测试人员在其框架下快速实现验收测试的自动化 ...

  3. C# 中关于汉字与16进制转换的代码

    /// <summary> /// 从汉字转换到16进制 /// </summary> /// <param name="s"></par ...

  4. java中容器的概念

    容器:顾名思义,装东西的器物至于spring中bean,aop,ioc等一些都只是实现的方式具体容器哪些值得我们借鉴,我个人觉得是封装的思想.将你一个独立的系统功能放到一个容器之中,可以当做一个大的接 ...

  5. 简单使用postman

    一.get请求 获取学生信息接口文档内容: 简要描述: 获取学生信息接口 请求URL: http://ip/api/user/stu_info 请求方式: get 参数: 参数名 必选 类型 说明 s ...

  6. cf555e

    cf555e(缩点) 给一个 n 个点 m 条边的图,以及 q 对点 (s,t),让你给 m 条边定向.问是否存在一种方案,使每对点的 s 能走到 t. \(n,m,q≤ 2×10^5\). 首先,在 ...

  7. HDU6318-2018ACM暑假多校联合训练2-1010-Swaps and Inversions-树状数组

    本题题意是,给你一个长度为n的序列,使用最少的操作把序列转换为从小到大的顺序,并输出操作数*min(x,y) 实质上是算出该序列中有多少逆序对,有归并排序和树状数组两种算法,由于数据之间的差值有点大, ...

  8. how to use windows azure market

    here is the sample. namespace USCrime2006and2007 { class Program { static void Main(string[] args) { ...

  9. 【转】IntelliJ IDEA下自动生成Hibernate映射文件以及实体类

    1.构建项目并添加项目结构配置以及配置初始参数 1.1.如图将基本的架子搭建好     1.2.点击File,弹出的菜单中点击Project Structure:     1.3.点击左侧的Modul ...

  10. tornado 09 cookie和session

    tornado 09 cookie和session 一.cookie #有什么办法能够让浏览器记住登录信息,下次再打开的时候可以自动登录?网站是如何记录登录信息的? class SetCookieHa ...