DWR反向Ajax示例(1)

1.javachat.jsp页面代码:
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
  <head>
    <title>DWR反向Ajax示例</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">
	<script type='text/javascript' src='/dwrtest/dwr/interface/JavaChat.js'></script>
  	<script type='text/javascript' src='/dwrtest/dwr/engine.js'></script>
	<script type='text/javascript' src='/dwrtest/dwr/util.js'></script>
	<script type="text/javascript">
		function displayMessage()
		{
			JavaChat.addRowMsg();
		}
		function sendMessage()
		{
			var title = $("title").value;
			var content = $("content").value;
			JavaChat.sendRow(title,content);
		}
	</script>
  </head>
  <body onload="displayMessage();"> 
  DWR反向Ajax示例信息添加<br>
    <p>
    	输入要添加的信息:
    	<br>主题:<input  type="text" id="title" name="title" onkeypress="dwr.util.onReturn(event,sendMessage)"><br>内容:<input  type="text" id="content" name="content" onkeypress="dwr.util.onReturn(event,sendMessage)">
    	<br><input type="button" value="发送" onclick="sendMessage();">
    </p>
  </body>
</html>

2.javachat1.jsp页面代码:
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
  <head>
    <title>DWR反向Ajax示例</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">
	<script type='text/javascript' src='/dwrtest/dwr/interface/JavaChat.js'></script>
  	<script type='text/javascript' src='/dwrtest/dwr/engine.js'></script>
	<script type='text/javascript' src='/dwrtest/dwr/util.js'></script>
	<script type="text/javascript">
		function sendMessage()
		{
			JavaChat.addRowMsg();
		}
	</script>
  </head>
  <body onload="DWREngine.setActiveReverseAjax(true);sendMessage();"> 
  DWR反向Ajax示例信息显示<br>
  	<div style=" height:240px; width:500px;overflow-y:auto;">
    	<table>
    		<tr>
    			<td>标题</td>
    			<td>内容</td>
    			<td>时间</td>
    		</tr>
    		<tbody id="msg"></tbody>
    	</table>
    </div>
  </body>
</html>

PS:下接DWR反向Ajax示例(2).

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