加入dwr.jar包
======jsp===============
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="javax.smartcardio.ATR"%>
<%@page import="java.util.LinkedHashMap"%>
<%@page import="java.util.HashMap"%>
<%@page import="com.lhwebcrm.commons.DataCommonFunction"%>
<%@page import="com.lhwebcrm.commons.CommonFunction"%>
<%@page import="com.lhwebcrm.bean.Xskhfl"%>
<%@page import="java.util.List"%>
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>客户关系管理系统-客户类型界面</title>
<c:set value="${pageContext.request.contextPath}" var="path"
scope="page" />
<!-- jquery,iframe不能使用主框架中已导入的js和css,所以必须在这里还要引入一次 -->
<script type="text/javascript"
src="${path}/js/jquery/jquery-1.7.2.min.js"></script>
<!-- 本模块具体的js -->
<script type="text/javascript"
src="${path}/js/qrykcsp.js?v=1.0" charset="utf-8"></script>
<!-- 如果有公用css,需要再此引入 -->
<!-- 模块具体的css -->
<link rel="stylesheet" type="text/css"
href="${path}/css/qrykcsp.css" />
<!-- .js固定写法 -->
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<!-- .js名称与dwr.XML配置名称一样 -->
<script type="text/javascript" src="dwr/interface/dwrQryKcspData.js"></script>
</head>
<body>
<div id="divMainContent">
<!-- bom属性 -->
<input type="hidden" id="hidbom_option" value=""/>
<!-- 价格类型 -->
<input type="hidden" id="hidpricetype" value="${pricetype}" />
<!-- 单据类型 -->
<input type="hidden" id="hidbilltype" value="${billtype}"/>
<!-- 是否可以多选 -->
<input type="hidden" id="hidismul" value="<%=ismul%>"/>
<!-- 条件区域 -->
<div id="divSearchArea">
关键字
<input type="text" id="txtKeyWord" value="${keyword}"/>
品牌
<input type="text" id="txtGuid_brand" value="${brandname}" hint="${guid_brand}"/>
<input type="checkbox" id="chkrslttype" checked="checked"/>高级查询
<br/>
编码
<input type="text" id="txtAcode"/>
名称
<input type="text" id="txtAname"/>
类型
<input type="text" id="txtKindname"/>
型号规格
<input type="text" id="txtAmodel"/>
<input type="checkbox" id="chkzero" /><span id="spanchkzero">包含零库存</span>
<br/>
标准型号
<input type="text" id="txtAmodel_param"/>
库位
<input type="text" id="txtGuid_place" value="${placename}" hint="${guid_place}"/>
<input type="radio" name="grpbomoption" id="radioAll" value="" checked="checked" onclick="setBomOptionValue(this.value);"/>全部
<input type="radio" name="grpbomoption" id="radioMaterial" value="材料" onclick="setBomOptionValue(this.value);"/>材料
<input type="radio" name="grpbomoption" id="radioHalfProduct" value="半成品" onclick="setBomOptionValue(this.value);"/>半成品
<input type="radio" name="grpbomoption" id="radioProduct" value="成品" onclick="setBomOptionValue(this.value);"/>成品
<input type="button" id="btnQuery" value="查询"/>
</div>
<TABLE class="tblresultM" id="tblresultM">
<THEAD id="tblresultHead">
</thead>
</table>
<TBODY id="tblresultBody">
==================js=========================
$j(function() {
// 查询方法
var pxxh = 0;
var ismul = "false";
ismul = $j("#hidismul").attr("value");
function getQryKcspList() {
var data;
data = {
"keyword" : $j("#txtKeyWord").attr("value"),// 关键字
"pricetype" : $j("#hidpricetype").attr("value"),// 价格类型
"rslttype" : $j("#chkrslttype").attr("checked"),// 人性化查询
"rsltqty" : $j("#chkzero").attr("checked"),// 带数量
"guid_brand" : $j("#txtGuid_brand").attr("hint"),
"brandname" : $j("#txtGuid_brand").attr("value"),
"acode" : $j("#txtAcode").attr("value"),
"aname" : $j("#txtAname").attr("value"),
"kindname" : $j("#txtKindname").attr("value"),
"amodel" : $j("#txtAmodel").attr("value"),
"amodel_param" : $j("#txtAmodel_param").attr("value"),
"guid_place" : $j("#txtGuid_place").attr("hint"),
"placename" : $j("#txtGuid_place").attr("value"),
"bom_option" : $j("#hidbom_option").attr("value"),
"billtype" : $j("#hidbilltype").attr("value")
};
dataResult = new Array();
dwrQryKcspData.getQryKcspResultByWhere(data, userListCallBack);// 调用查询的方法
pxxh = 0;
}
var map;
// 查询后的回调函数获取list(resultTabelCallBack)
function userListCallBack(resultTabelCallBack) {
if (resultTabelCallBack.length <= 0) {
DWRUtil.removeAllRows("tblresultBody");
return;
}
map = resultTabelCallBack[0];
DWRUtil.removeAllRows("tblresultHead");
//DWRUtil.addRows("tblresultHead", resultTabelCallBack, cellFun1);
var trHead = document.createElement("tr");
var tdselect = document.createElement("td");
tdselect.innerHTML = "选择";
trHead.appendChild(tdselect);
var tdxh = document.createElement("td");
tdxh.innerHTML = "序号";
trHead.appendChild(tdxh);
for ( var key in map) {
var td = document.createElement("td");
td.innerHTML = key;
if (key.indexOf("guid") >= 0) {
td.style.display = "none";
}
trHead.appendChild(td);
}
document.getElementById("tblresultHead").appendChild(trHead);
DWRUtil.removeAllRows("tblresultBody");
for ( var i = 0; i < resultTabelCallBack.length; i++) {
var mapchild = resultTabelCallBack[i];
var trbody = document.createElement("tr");
var tdselect = document.createElement("td");
if (ismul == "false") {
tdselect.innerHTML = "<input type='radio' name='radioselect'/>";
} else {
tdselect.innerHTML = "<input type='checkbox' name='chkselect'/>";
}
trbody.appendChild(tdselect);
var tdxh = document.createElement("td");
tdxh.innerHTML = i + 1;
trbody.appendChild(tdxh);
for ( var key in map) {
var td = document.createElement("td");
if (mapchild[key] != null && mapchild[key] != "null") {
td.innerHTML = mapchild[key];
} else {
td.innerHTML = "";
}
td.setAttribute("fldname", key);
if (key.indexOf("guid") >= 0) {
td.style.display = "none";
}
trbody.appendChild(td);
}
trbody.className = "trResult";
trbody.onclick = function() {
trResultClick(this.rowIndex);
};
document.getElementById("tblresultBody").appendChild(trbody);
}
}
// 查询
$j("#btnQuery").click(function() {
getQryKcspList();
});
=========action=====================
// 通用商品查询
public String getQryKcspResult(){
try {
String selAcode = request.getParameter("selacode");//确定该使用什么查询语句
String keyword = request.getParameter("keyword");//关键字
String ismul = request.getParameter("ismul");//是否可以多选
String pricetype = request.getParameter("pricetype");//价格类型
String bkc = request.getParameter("bkc");//是否包含零库存
keyword = new String(keyword.getBytes("ISO-8859-1"),"GBK");
System.out.println(selAcode);
System.out.println(keyword);
List<LinkedHashMap<String, String>> lsqls = DataCommonFunction.getResultData("select wheresql from syskeyfield where acode='"+selAcode+"'");
String lsqltmp = "";
if (lsqls.size()>0) {
lsqltmp = lsqls.get(0).get("wheresql").toString();
}
System.out.println(lsqltmp);
lsqltmp = lsqltmp.replaceAll("\'\[value\]\'", "");
lsqltmp = lsqltmp.replaceAll("exec", "");
System.out.println(lsqltmp);
StringBuffer lsql = new StringBuffer();
lsql.append("{call ").append(lsqltmp).append("(@keyword='").append(keyword).append("')").append("}");
System.out.println(lsql.toString());
qrykcsps = DataCommonFunction.getResultData(lsql.toString());
System.out.println(qrykcsps.toString());
List<LinkedHashMap<String,String>> xsbrandmanagements = DataCommonFunction.getResultData("select aguid,aname from xsbrandmanagement order by aname");
List<LinkedHashMap<String,String>> kcplaces = DataCommonFunction.getResultData("select aguid,aname from kcplace order by aname");
if (keyword!=null && !"".equals(keyword) && !"null".equals(keyword)) {
if(keyword.indexOf("|")<0){
request.setAttribute("keyword", keyword);
}else{
String[] astr = keyword.split("|");
//品牌
if(astr[0]!=null && !"".equals(astr[0])){
request.setAttribute("guid_brand", astr[0]);
String brandname = DataCommonFunction.getFld0Value("select top 1 aname from xsbrandmanagement where aguid='"+astr[0]+"'");
request.setAttribute("brandname", brandname);
}
//库位
if(astr[1]!=null && !"".equals(astr[1])){
request.setAttribute("guid_place", astr[1]);
String placename = DataCommonFunction.getFld0Value("select top 1 aname from kcplace where aguid='"+astr[1]+"'");
request.setAttribute("placename", placename);
}
//区域经理
if(astr[2]!=null && !"".equals(astr[2])){
}
//单据类型
if(astr[3]!=null && !"".equals(astr[3])){
request.setAttribute("billtype", astr[3]);
}
//剩下 的关键字
if(astr[4]!=null && !"".equals(astr[4])){
request.setAttribute("keyword", astr[4]);
}
}
}
request.setAttribute("XSBRANDMANAGEMENTS", xsbrandmanagements);
request.setAttribute("KCPLACES", kcplaces);
request.setAttribute("ISMUL", ismul);
request.setAttribute("pricetype", pricetype);
request.setAttribute("bkc", bkc);
} catch (Exception e) {
e.printStackTrace();
return "error";
}
return "qrykcsp";
}
=====dwr.xml===============
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<create javascript="dwrQryKcspData" creator="spring">
<param name="beanName" value="commonActionBean"></param>
</create>
<convert match="com.lhwebcrm.bean.*" converter="bean"></convert>
</allow>
</dwr>
=============web。xml=====================
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>webCRM</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- dwr -->
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>