当前位置: 代码迷 >> Web前端 >> DWR 传送对象-参数 DEMO
  详细解决方案

DWR 传送对象-参数 DEMO

热度:1044   发布时间:2012-11-22 00:16:41.0
DWR 传递对象--参数 DEMO
具体配置参考前几个DWR DEMO

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import = "com.dwr.UserBean" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'dwrTest2.jsp' starting page</title>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="<%=path %>/dwrjs/util.js"></script>
	<script type="text/javascript" src="<%=path %>/dwrjs/engine.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/interface/testDwrService.js"></script>
  	<script type="text/javascript">
  		function showSelect(){
  			// test 定义一个对象
  			var data ={id:3,userName:DWRUtil.getValue('uid'),psw:DWRUtil.getValue('pid')};
  			//var data ={id:3,userName:"yonghuming",psw:"mima"};
  			alert(data);
  			testDwrService.passObject(data,function(result){
  				alert(result);
  			});
  		}
  	</script>
  </head>
  <body style="margin-left: 300px">
    This is my JSP page. <br>
    <form action="#" method="post" name="frm">
    	<input type="button" value="Button" onclick="showSelect()"/>
    	
    	<input type="hidden" id="uid" value="用户名">
    	<input type="hidden" id="pid" value="密码">
    </form>
  </body>
</html>


//	dwr 传递对象 passObject
	public String passObject(UserBean user){
		System.out.println(user.getId()+"" +
				" "+user.getPsw()+" "+user.getUserName());
		return "passObject";
	}

<allow>
        <create creator="new" javascript="testDwrService">
            <param name="class" value="com.dwr.TestDwrService2" />
        	<include method="passObject" />
        </create>
        <convert converter="bean" match="com.dwr.UserBean">
        	<param name="include" value="id,userName,psw"></param>
        </convert>
    </allow>
  相关解决方案