DWR 返回对象 DEMO

具体配置参照我上一篇DWR配置

<%@ 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(){
  			testDwrService.returnObject(function(data){
  				alert(data.id+" "+data.userName+" "+data.psw);
  			});
  		}
  	</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="hiddenId" value="returnObjectTest">
    </form>
  </body>
</html>

public UserBean returnObject(){
		System.out.println("returnObject ....03");
		UserBean user = new UserBean();
		user.setId(1);
		user.setUserName("userName");
		user.setPsw("psw");
		return user;
	}
<allow>
        <create creator="new" javascript="testDwrService">
            <param name="class" value="com.dwr.TestDwrService2" />
        	<include method="returnObject" />
        </create>
        <convert converter="bean" match="com.dwr.UserBean">
        	<param name="include" value="id,userName,psw"></param>
        </convert>
    </allow>

你可能感兴趣的:(java,html,jsp,DWR)