Applet学习教程(一):applet+dwr 实现
后台代码
import java.applet.Applet; import java.util.HashMap; import java.util.Map; import netscape.javascript.JSObject; public class OrderRemindApplet extends Applet { private static final long serialVersionUID = 1L; public static final int PORT = 12333; JSObject win; JSObject doc; String[] args = new String[10]; Thread timer; String salesGroupCode="";// boolean flag=false; @Override public void init() { System.out.println("init;;;"); try { this.win = JSObject.getWindow(this); this.doc = ((JSObject)this.win.getMember("document")); salesGroupCode = getParameter("salesGroupCode"); } catch (Exception e) { System.out.print(e.getMessage()); } } public String getOrderCounts(String salesgcodePar){ System.out.println("getOrderCounts;;;"); Map<String, Object> mapPara = new HashMap<String, Object>(); mapPara.put("salesgcode", salesgcodePar); String result= "商号"+salesgcodePar+",N个订单,超过30分钟未处理,请去服务监控页面处理"; return result; } @Override public void destroy() { System.out.println("destroy;;;"); } @Override public void start(){ System.out.println("start;;;"); } }
前台代码
<%@ 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"> <title>Insert title here</title> <script type='text/javascript' src='dwr/interface/OrderRemindApplet.js'></script> <script type='text/javascript' src='dwr/engine.js'></script> <script type='text/javascript' src='dwr/util.js'></script> <script> //这个方法用来启动该页面的ReverseAjax功能 dwr.engine.setActiveReverseAjax( true); var salesGroupCode="641"; function startRe(){ OrderRemindApplet.getOrderCounts(salesGroupCode,callBackFun); setTimeout(startRe,20*1000); } function callBackFun(result){ alert(result); } </script> </head> <body onload="startRe();" > <applet name="OrderRemindApplet" code="OrderRemindApplet" width="100" height="200" codebase="." code="OrderRemindApplet.class" > <param name=salesGroupCode value="641"> </applet> </body> </html>
dwr2.0 配置
<?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="OrderRemindApplet" scope="session"> <param name="class" value="OrderRemindApplet"/> </create> </allow> </dwr>
jar 文件