web.xml 配置:
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
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 creator="new" javascript="FirstDWR">
<param name="class" value="com.zte.gateway.web.am.action.FirstDWR" />
</create>
<convert match="com.zte.gateway.web.am.action.StringOBJ" javascript="StringOBJ"
converter="bean" />
</allow>
</dwr>
页面:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/util.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/dwr/interface/FirstDWR.js"></script>
<script type="text/javascript">
function goshow(){
FirstDWR.returnStrs("aaa",getResult);
}
var cellFuncs = [function(StringOBJ) { return StringOBJ.str; }];
function getResult(result){
dwr.util.setEscapeHtml(false);
var options = {
cellCreator:function(options){
var td = document.createElement("td");
return td;
}
};
dwr.util.addRows("pattern",result,cellFuncs,options);
}
//定时执行
//setInterval("goshow()",1000);
</script>
<title>Insert title here</title>
</head>
<body>
<input type="button" onclick="goshow()" value="查 询"/>
<table class="tdata w_4">
<thead><tr><th>值</th></tr></thead>
<tbody id="pattern"/>
<tfoot><tr><td colspan="4" class="tright"></td></tr></tfoot>
</table>
</body>
</html>