`
林里风咏
  • 浏览: 12397 次
  • 性别: Icon_minigender_1
  • 来自: 湖南长沙
最近访客 更多访客>>
社区版块
存档分类
最新评论

DWR为什么弹出了类名,而不进方法

 
阅读更多
写一个输入信息框,填写编号时,检查编号是不是存在,用DWR测试时候弹出了对应的类名而没有进入类里面的方法(方法里面有断点)。请哪位指点一下,错误在什么地方,不胜感谢!!
dao类:
public int checkNo(String productId) {
		int count = 0;
		// String productId = form.getProductId();
		String sql = "select a.* from product a where a.product_id=?";
		System.out.println("sql:====" + sql);
		List list = new ArrayList();
		Connection con = ConnectionDB.getDataSource();
		try {
			PreparedStatement pst = con.prepareStatement(sql);
			pst.setString(1, productId);
			ResultSet set = pst.executeQuery();
			while (set.next()) {
				list.add(set.getString(1));
				list.add(set.getString(2));
				list.add(set.getString(3));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (list.size() > 0) {
			count = 1;
		} else {
			count = 0;
		}
		return count;
	}



JSP页面:在这个页面输入产品编号以后,失去焦点就检查是不是存在编号,调用JS里面方法,但就是不行:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%
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>录入产品信息</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="css/table.css">
	<link rel="stylesheet" type="text/css" href="css/form.css">
	<link rel="stylesheet" type="text/css" href="css/vbulletin.css">
	
	
	<script type='text/javascript' src='/ZStruts/dwr/interface/JCheckNo.js'></script>
    <script type='text/javascript' src='/ZStruts/dwr/engine.js'></script>
    <script type='text/javascript' src='/ZStruts/dwr/util.js'></script>

	
	
	<script type="text/javascript">
		function checkProductNo(flag){
		var productNo = flag.value;
			if(productNo==""){
				alert("编号不能为空");
				flag.focus();
				return;
			}else{
			alert("======");
			JCheckNo.checkNo(productNo,check);}
		}
		
		function check(flag){
			alert(flag);
			if(flag==1){
				alert("编号已存在!");
				document.forms[0].elements["productId"].focus();
			}
		}
		
	</script>

  </head>
  
  <body>
  		<br/>
  		<br/>
    	<html:form action="saveProductList.do">
    	 <table align="center">
    	 	<caption><font size="5">录入产品信息</font></caption>
    	 	<tr>
    	 		<td>产品编号</td>
    	 		<TD><html:text property="productId" onblur="checkProductNo(this)" ></html:text></TD>
    	 	</tr>
    	 	<tr>
    	 		<td>产品名称</td>
    	 		<TD><html:text property="productName"></html:text></TD>
    	 	</tr>
    	 	<tr>
    	 		<td>产品价格</td>
    	 		<TD><html:text property="productPrice"></html:text></TD>
    	 	</tr>
    	 	<tr >
    	 		<td colspan=2>
    	 			<html:submit value="保存"></html:submit>
    	 		</td>
    	 	</tr>
    	 </table>
    	</html:form>
  </body>
</html>



Struts配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
	<data-sources />
	<form-beans>
		<form-bean name="saveProductForm" type="cn.com.jasonlee.form.ProductFrom"></form-bean>
		<form-bean name="searchProductForm" type="cn.com.jasonlee.form.ProductFrom"></form-bean>
		<form-bean name="testDwr" type="cn.com.jasonlee.form.ProductFrom"></form-bean>
	</form-beans>
	<global-exceptions />
	<global-forwards>
		<forward name="saveProduct" path="/SaveProduct.jsp"></forward>
		<forward name="searchProduct" path="/SearchProduct.jsp"></forward>
	</global-forwards>
	<action-mappings>
		<action name="saveProductForm" path="/saveProductList" scope="request"
			type="cn.com.jasonlee.action.SaveProductAction">
			<forward name="save" path="/Save.jsp"></forward>
		</action>
		<action name="searchProductForm" path="/searchProduct" scope="request"
			type="cn.com.jasonlee.action.SearchProductAction">
			<forward name="search" path="/search.jsp"></forward>
		</action>
		<action name="testDwr" path="/testDwr" scope="request"
			type="cn.com.jasonlee.test.TestDwr">
			<forward name="save" path="/Save.jsp"></forward>
		</action>
	</action-mappings>
	<message-resources parameter="struts.ApplicationResources" />
</struts-config>


DWR配置文件
<?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>
		//在jsp 页面里面通过JUserInfoBiz来调用checkName方法
		<create javascript="JCheckNo" creator="new">
			// 你所调用的是哪一个类
			<param name="class" value="cn.com.jasonlee.dao.ProductDao" />
			// 这个类里面的方法的名称
			<include method="checkNo" />
		</create>
		<create javascript="TestDWR" creator="new">
			// 你所调用的是哪一个类
			<param name="class" value="cn.com.jasonlee.test.TestDwr" />
			// 这个类里面的方法的名称
			<include method="hello" />
		</create>
		<convert converter="bean" match="java.lang.StackTraceElement" />  
		<convert converter="exception" match="java.lang.Exception"/> 
	</allow>
</dwr>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics