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. 【单例模式】Singleton pattern

    前言:有很多时候,在一个生命周期中我们只要一个对象就可以了,比如:线程池,缓存,对话框,日志,显卡驱动等等.如果造出多个实例,就会导致许多问题产生,例如:程序的行为异常.资源使用过量,或者说不一致的结 ...

  2. 引用母版页的内容页添加CSS文件

    在内容页当中定义一个类然后调用内中的方法即可 public static class addstyle{  //可以不用实例化 public static void addstylesheet(Pag ...

  3. 关于eWebEditorAPI

    1.获取HTML document.getElementById(Iframe的名称).contentWindow.getHTML();在线API http://www.ewebeditor.net/ ...

  4. Ubuntu下添加Python环境变量

    最近把自己在windows上的Django项目放在的Ubuntu上,启动时提示找不到模块 原来是自己的项目用的是虚拟环境,安装的第三方库全部在虚拟环境中 AutoTestSite/venv/Lib/s ...

  5. 关于MVC刷新页面会两次请求页面的原因

    遇到这个奇葩的问题刚开始关注点全放在后台了 ,以为后台哪个地方存在问题,找了半天一无所获之后才开始把问题关注点移到前端,通过不断的注释前台代码, 终于发现了问题,没想到是这个js导致的问题 因为的Vi ...

  6. DataTable中的select()用法

    1.在DataTable中执行DataTable.Select("条件")返回DataTable // <summary> // 执行DataTable中的查询返回新的 ...

  7. MultiDataTrigger

    MultiDataTrigger是多条件数据触发器 和MltiTrigger是同样的,只不过前者是数据,后者是属性. 这个是基本的使用语法 <MultiDataTrigger> <M ...

  8. 离线安装 python 第三方库

     离线安装 python 第三方库 首先你需要在联网的服务器上已经安装了一个第三方库,比如是paramiko,也就是说你已经执行了 pip install paramiko    ,小提示: 如果在安 ...

  9. 190225Redis

    一.Redis的简单使用 Redis操作模式 # Author:Li Dongfei import redis r = redis.Redis(host='192.168.56.7', port=63 ...

  10. 2B - Amy

    数据范围是18位,把每一位加起来的和最多9*18 = 162 所以只需考虑n-162 - n的数即可,暴力解决 #include <iostream> using namespace st ...