??xml version="1.0" encoding="utf-8" standalone="yes"?>极品白浆推特女神在线观看
,在线日韩影院,夜夜精品视频 http://www.aygfsteel.com/mstar/category/2359.html搞Y件开发就像被强奸,如果不能反抗,׃n受它吧! zh-cn Tue, 27 Feb 2007 18:34:38 GMT Tue, 27 Feb 2007 18:34:38 GMT 60 用DWR2.0做的一个Server日志查看?/title> http://www.aygfsteel.com/mstar/archive/2007/01/03/Ajax_DWR2_LogViewer.html黑灵 黑灵 Wed, 03 Jan 2007 14:21:00 GMT http://www.aygfsteel.com/mstar/archive/2007/01/03/Ajax_DWR2_LogViewer.html http://www.aygfsteel.com/mstar/comments/91645.html http://www.aygfsteel.com/mstar/archive/2007/01/03/Ajax_DWR2_LogViewer.html#Feedback 4 http://www.aygfsteel.com/mstar/comments/commentRss/91645.html http://www.aygfsteel.com/mstar/services/trackbacks/91645.html 有时候我需要查看已l部|到服务器上的应用程序的日志Q每ơ都要远E登录服务器感觉很麻烦,所以一般我会把log文g的目录用apache做个|站Q这样通过IE可以访问到了。但是有时要看即时输出情况,p不断的F5Q很ȝ。所以就有个xQ不如用DWR2.0的反转Ajax来做个程序,让日志有变化时自动的发送到客户端,q样我一个劲的按F5了?br /> 我下面就把这个程序分享给大家Q希望大家提提意见?br /> 首先是环境: DWR 2.0.rc1 Sun JDK 1.5 先看张运行v来的囑Q大家一看就知道q是个什么东西了?br /> 你可以制定要监视的log文gQ当然有哪些文g文g可以被监视,你必d服务端的xml配置中文件设|,当然你也可以监视一个目录里的log文gQ这对于而log文g是每天生成一个的情况很有用。你可以讑֮在浏览器上显C的行数Q操作行敎ͼ屏幕会自动滚动。你q可以添加一些过滤器Q过滤掉不想看见的行Q我目前只做了到了过滤掉一些信息,当然如果你有兴趣Q你也再d一些更复杂的过滤器。过滤器的模式是用正则表辑ּ表示的?br /> 下面是点几Z开始监听”,q行后样?br /> 如果服务器上的catalina.2006-12-09.log文g发生变化Q客L的浏览器上log昄Z会自动的向上滚动?br /> 下面我就大致的介l一下如何用DWR2.0来实现这L功能。在q里介绍的可能不是很详细Q不清楚的地方请看我提供的源码?br /> 先来介绍一下目录结?br />├─lib -- ~译和测试用的第三方cd ├─webapp -- 部v目录 ├─test -- 试E序 ├─java -- ȝ?br />└─build.xml -- ant构徏文g webapp下的文g和目?br />│?style.css -- 样式表文?br />│?index.html -- ȝ面文?br />?br />├─WEB-INF │?│?web.xml -- 部v配置文g │?│?dwr.xml -- dwr的配|文?br />│?│?conf.xml -- 我们q个应用E序配置文gQ主要是配置log文g │??br />│?├─classes │??br />│?└─lib ?br />└─script -- javascript文g index.html中就是我们上面的囄上能看到的页面元素。其中的控g的事件处理都写在\script\logviewer.js文g中?br />
当页面加载时执行startPoll()ҎQ复杂开始与服务器的通信Qƈ且把log文g选择框初始化Q把已经dqo器列表显C出来?
function
startPoll() { DWREngine.setActiveReverseAjax(
true
); LogManager.getLogFileNames(
function
(data) { DWRUtil.removeAllOptions(
"
log_file
"
); DWRUtil.addOptions(
"
log_file
"
, data); }); LogManager.getFilters(
function
(data) {
for
(
var
i
=
0
; i
<
data.length; i
++
) { addFilterDiv(data[i].pattern, data[i].id); } }); }
当点几Z开始监听”按钮时调用服务端的LogManager的sendҎQ服务端开启监听线E,开始监听做为参C递的文gQ如果文件有变动׃把最q增加的行发送到览器上来?
var
startWatch
=
function
() { clearLog(); LogManager.send(DWRUtil.getValue(
"
log_file
"
)); }
当点几Z结束监听”按钮,调用LogManager的stop()ҎQ结束掉监听U程?br />
function
stopWatch() { LogManager.stop(); }
当点几Z清I日志”按钮,清除mainPanel中的所有子元素
function
clearLog() {
var
mainPanel
=
$(
"
main_panel
"
);
while
(mainPanel.hasChildNodes()) { mainPanel.removeChild(mainPanel.firstChild); } }
当点几Z添加过滤器”,填充输入框,要求输入做ؓqo器的正则表达式,输入完成后,要做两g事: 1、LogManager.addFilterҎQ把输入的正则表辑ּ传送给服务端?br />2、把q个正则表达式添加到面上?/p>
function
addFilter() {
var
regex
=
prompt(
"
输入正则表达?/span>
"
,
""
);
if
(regex
!=
null
&&
regex
!=
""
) { LogManager.addFilter(regex,
function
(filterId) { addFilterDiv(regex, filterId); }); } }
注意q里Q我们用CDWR的回调模式,在调用服务端ҎLogManager.addFilter成功后我们才调用客户端的addFilterDivҎ把这个输入的正则表达式显C到面上?br /> 如果你够细心的话,应该会发现在q个js文g中有一个叫做addNewLine的方法在index.html中是没有被调用的。这个方法其实是l服务端的LogManager.send函数调用的?br /> 上面q些内容是服务端脚本的主要内容了,其实很简单。主要负责通过DWR与服务端通信和处理页面显C?br /> 下面介绍服务端的核心c:LogManager q个cM要就q样几个ҎQ?br /> /** * 停止监控 */ public void stop() { if (watcher != null ) { watcher.halt(); } } /** * 发送log信息 */ public void send(String filename) { WebContext wctx = WebContextFactory.get(); final ScriptSession scriptSession = wctx.getScriptSession(); if (watcher != null ) { watcher.halt(); } try { watcher = new LogFileWatcher(filename); watcher.addListener( new LogUpdateListener() { public void onLogUpdate(List < String > lines) { for (String line : lines) { if (checkFilters(line)) { ScriptBuffer scriptBuffer = new ScriptBuffer(); scriptBuffer.appendScript( " addNewLine( " ) .appendData(line) .appendScript( " ); " ); scriptSession.addScript(scriptBuffer); } } } }); watcher.start(); } catch (IOException e) { ScriptBuffer scriptBuffer = new ScriptBuffer(); scriptBuffer.appendScript( " addNewLine( " ) .appendData(e.getMessage()) .appendScript( " ); " ); scriptSession.addScript(scriptBuffer); log.warn(e); } } /** * 取得指定的日志文件\?br /> * * @return 指定的日志文件\?br /> */ public List < String > getLogFileNames() { List < String > filenames = new ArrayList < String > (); try { XMLConfiguration config = getConfiguration(); List logfiles = config.getList( " log-files.file " ); for (Object o : logfiles) { filenames.add((String) o); } } catch (ConfigurationException e) { log.warn(e); } return filenames; } /** * 取得指定的日志目录下的文?br /> * * @return 指定的日志目录下的文?br /> */ public List < String > getLogFileNamesFromDir() { List < String > filenames = new ArrayList < String > (); try { XMLConfiguration config = getConfiguration(); String dir = config.getString( " log-dir.dir " ); if (dir != null ) { File rootDir = new File(dir); if (rootDir.exists()) { if (rootDir.isFile()) { filenames.add(rootDir.getPath().replace( ' \\ ' , ' / ' )); } else if (rootDir.isDirectory()) { String patternString = config.getString( " log-dir.filter " ); File[] files; if (patternString != null && ! patternString.equals( "" )) { files = rootDir.listFiles( new LogFileFilter(patternString)); } else { files = rootDir.listFiles(); } for (File file : files) { filenames.add(file.getPath().replace( ' \\ ' , ' / ' )); } } } } } catch (ConfigurationException e) { log.warn(e); } return filenames; } /** * d一个过滤器Q返回过滤器的id */ public int addFilter(String regex) { synchronized (filters) { Filter filter = new Filter(regex, SequenceGenerator.getInstance().next(), FilterType.INCLUDE); filters.add(filter); return filter.getId(); } } /** * Ҏid删除一个过滤器 */ public void removeFilter( int id) { synchronized (filters) { filters.remove( new Filter(id)); } } /** * 取得现在所有的qo器列?br /> */ public List < Map < String, Object >> getFilters() { List < Map < String, Object >> result = new ArrayList < Map < String, Object >> (); synchronized (filters) { for (Filter filter : filters) { Map < String, Object > filterItem = new HashMap < String, Object > (); filterItem.put( " id " , filter.getId()); filterItem.put( " pattern " , filter.getPattern().pattern()); result.add(filterItem); } } return result; }
对于大家都做qJava的朋友来_q些代码应该很容易就能看懂,我就不多说了。大家主要注意一下ScriptSessionc,q个cd是vC要功能的cM?br /> 其中的LogFileWatcher是一个Threadc,它是用来监视log文g的?br /> SequenceGenerator.java是用来生成过滤器的id的?br /> LogUpdateListener.java是一个接口,用于实现事g回调的?br /> 然后看一个dwr的配|文?br />< dwr > < allow > < create creator ="new" javascript ="LogManager" scope ="session" > < param name ="class" value ="org.devside.logviewer.LogManager" /> < include method ="send" /> < include method ="stop" /> < include method ="getLogFileNames" /> < include method ="getLogFileNamesFromDir" /> < include method ="addFilter" /> < include method ="removeFilter" /> < include method ="getFilters" /> </ create > </ allow > </ dwr >
q里的配|文件和1.x几乎没什么两P是scope我这里设|成了session范围的。这样就可以多个人同时监视不同的log文g了?br /> web.xml文g也基本上是老样?br /><? xml version="1.0" encoding="UTF-8" ?> < web-app id ="LogViewer" version ="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > < display-name > Web Log Viewer </ display-name > < servlet > < description > Direct Web Remoter Servlet </ description > < display-name > DWR Servlet </ display-name > < 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 > < init-param > < param-name > pollAndCometEnabled </ 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 > < welcome-file-list > < welcome-file > index.html </ welcome-file > </ welcome-file-list > </ web-app >
dwr的包名发生了变化Qƈ且要开启反转ajaxQ就要把pollAndCometEnabled参数讄为true?br /> ȝQM来说DWR2.0中的反{ajaxq是很容易用的Q这也是dwr的一贯风|不用知道q多的细节就能容易的实现ajax。dwrl对是Java开发者的首选ajax框架?br />另外我这个程序其实还是ؓ了演C用的,如果惌用户实际开发可能还需要修改,比如安全性上面,性能上面。而性能上面的主要问题是客户端浏览器Q如果服务端的log文gq大Q而浏览器有不能即时的回收内存Q就会造成客户端浏览器内存占用q大而死掉的问题。而服务端׃java的内容回收机制已l比较成熟应该不会有什么问题。我在ie6和firefox2都试q了Qfirefox效果能好一些?br /> 源码下蝲Q?br />http://www.aygfsteel.com/Files/mstar/LogViewer.part1.rar http://www.aygfsteel.com/Files/mstar/LogViewer.part2.rar ]]>把DWR的配|写到Spring的配|文仉QSpring2 新特?自定义schema初体验) http://www.aygfsteel.com/mstar/archive/2006/11/16/81542.html黑灵 黑灵 Thu, 16 Nov 2006 07:50:00 GMT http://www.aygfsteel.com/mstar/archive/2006/11/16/81542.html http://www.aygfsteel.com/mstar/comments/81542.html http://www.aygfsteel.com/mstar/archive/2006/11/16/81542.html#Feedback 5 http://www.aygfsteel.com/mstar/comments/commentRss/81542.html http://www.aygfsteel.com/mstar/services/trackbacks/81542.html 你要知道Spring是什么,q且要知道Spring已经Z2.0的版本了?br />你要知道DWR是什么,q且要知道DWR也要?.0的版本了?br /> 呵呵Q开个玩W……。这q头在BlogJava上的,估计没几个不知道上面q两个项了?br /> 好了Q现在言归正传。DWR本n提供对Spring的支持,可以直接把Spring中的Bean暴露l客L览器的Javascript调用。在dwr.xml中的写法是这LQ?br />< dwr > < allow > < create creator ="spring" javascript ="AjaxPortalService" > < param name ="beanName" value ="AjaxPortalService" /> < include method ="changeWondowState" /> < include method ="changeWorkbenchState" /> < include method ="changeWindowOrder" /> </ create > </ allow > </ dwr >
q样写到也没什么,只是把项目分模块以后Q虽有的配置都写C个dwr.xml文g里面l护h比较ȝQ尤其再遇到版本理中的代码合ƈ。所以曾l我扩展了DWRQ让它可以从多个文gd配置信息。然后每个模块自׃个配|文Ӟ跟着source一赯。这样做也有问题Q就是现在Java应用E序的配|文件太多啦QSpring的配|,WebWork的配|,Hibernate的配|,DWR的配|,再加上一些杂七杂八的xml和properties。看着q些配置文g直要疯掉了?br /> 正在此时Qspring2横空ZQ现在你可以把一些配|文件合q到一起了。正好趁此机会体验一下Spring2的自定义schemaҎ?br /> 目标Q?br />把DWR的配|写成这P<? xml version="1.0" encoding="GBK" ?> < beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:dwr="http://www.devside.org/schema/spring/dwr" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.devside.org/schema/spring/dwr http://www.devside.org/schema/spring/dwr.xsd" default-autowire="byName" > < bean id ="departmentDao" class ="cn.com.legendapl.hellostruts2.dao.DepartmentDao" /> < bean id ="employeeDao" class ="cn.com.legendapl.hellostruts2.dao.EmployeeDao" /> < bean id ="companyService" class ="cn.com.legendapl.hellostruts2.service.CompanyService" /> < aop:config > < aop:pointcut id ="companyServiceOperation" expression ="execution(* cn.com.legendapl.hellostruts2.service.ICompanyService.*(..))" /> < aop:advisor advice-ref ="txAdvice" pointcut-ref ="companyServiceOperation" /> </ aop:config > < bean id ="ajaxCompanyProxy" class ="cn.com.legendapl.hellostruts2.ajax.AjaxCompanyProxy" /> < dwr:allow id ="ajaxCompanyProxyAllow" > < dwr:create beanName ="ajaxCompanyProxy" javascript ="CompanyProxy" > < dwr:include method ="findEmployeeById" /> </ dwr:create > < dwr:convert converter ="bean" match ="cn.com.legendapl.hellostruts2.entity.*" /> </ dwr:allow > </ beans >
重点在这里: < dwr:allow id ="ajaxCompanyProxyAllow" > < dwr:create beanName ="ajaxCompanyProxy" javascript ="CompanyProxy" > < dwr:include method ="findEmployeeById" /> </ dwr:create > < dwr:convert converter ="bean" match ="cn.com.legendapl.hellostruts2.entity.*" /> </ dwr:allow >
好了现在动手开始做?br /> 原理其实很简单,现在看张图。画的不好,敬请原谅Q?br /> 从这样图中我们可以看出我们要做如下工作: 1、做一个dwr.xsdQ定义spring配置文g中的dwrq部分配|的schema?br /> 要做q个需要有一定xml和xsd的知识,我也是现学现用啦Q?br />
<? xml version="1.0" encoding="UTF-8" ?> < xsd:schema xmlns ="http://www.devside.org/schema/spring/dwr" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans" targetNamespace="http://www.devside.org/schema/spring/dwr" elementFormDefault ="qualified" attributeFormDefault ="unqualified" > < xsd:import namespace ="http://www.springframework.org/schema/beans" schemaLocation ="http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" /> < xsd:element name ="allow" > < xsd:complexType > < xsd:complexContent > < xsd:extension base ="beans:identifiedType" > < xsd:sequence > < xsd:element name ="create" type ="createType" minOccurs ="0" maxOccurs ="unbounded" /> < xsd:element name ="convert" type ="convertType" minOccurs ="0" maxOccurs ="unbounded" /> </ xsd:sequence > </ xsd:extension > </ xsd:complexContent > </ xsd:complexType > </ xsd:element > < xsd:complexType name ="createType" > < xsd:sequence > < xsd:element name ="auth" type ="authType" minOccurs ="0" maxOccurs ="unbounded" /> < xsd:element name ="include" type ="includeType" minOccurs ="0" maxOccurs ="unbounded" /> < xsd:element name ="exclude" type ="excludeType" minOccurs ="0" maxOccurs ="unbounded" /> </ xsd:sequence > < xsd:attribute name ="beanName" type ="xsd:string" use ="required" /> < xsd:attribute name ="javascript" type ="xsd:string" use ="required" /> </ xsd:complexType > < xsd:complexType name ="convertType" > < xsd:attribute name ="converter" type ="xsd:string" use ="required" /> < xsd:attribute name ="match" type ="xsd:string" use ="required" /> </ xsd:complexType > < xsd:complexType name ="authType" > < xsd:attribute name ="method" type ="xsd:string" use ="required" /> < xsd:attribute name ="role" type ="xsd:string" use ="required" /> </ xsd:complexType > < xsd:complexType name ="includeType" > < xsd:attribute name ="method" type ="xsd:string" use ="required" /> </ xsd:complexType > < xsd:complexType name ="excludeType" > < xsd:attribute name ="method" type ="xsd:string" use ="required" /> </ xsd:complexType > </ xsd:schema > 2、我们要做一个DWRNamespaceHandler来处理DWR的配|信息,其实里面做一件事把AllowBeanDefinitionParser注册lallow节点。因为我们dwr的配|部分根节点׃个标{allowQ所以我们就做一个用于解析allow标签的AllowBeanDefinitionParser解析器就行。如果我们的根节点还有其他的标签Q同样也要做相应的解析器?br />
public class DWRNamespaceHandler extends NamespaceHandlerSupport { public void init() { // 把AllowBeanDefinitionParser注册到allow节点 registerBeanDefinitionParser( " allow " , new AllowBeanDefinitionParser()); } }
其实隄是做AllowBeanDefinitionParserQ这里你需要一些DOM模型的知识,来操作配|节点的内容。然后根据内容进行处理。在q里我们Q需要做三g事: [1] 把配|节点的内容转换成对象模型,即AllowBeanQ其实就是一些POJO|了Q?br /> [2] 把这个AllowBean注册lSpring的ContextQ这一步是可选的。因为我们主要是把这个BeanlDWRQ当焉道给Spring一份也没什么问题?br /> [3] 把这个AllowBean注册到AllowBeanHolder?br /> 3、AllowBeanHolder?br /> 其实q就是个单的singletonc,整个q行期只有一个实例。它像一个容器,AllowBeanDefinitionParser往里放QDWR的Configuration再从q里取?br /> 4、扩展DWR的DefaultConfigurationQ我们做一个SpringConfiguration。DWR的DefaultConfiguration是负责读取配|信息的。我们在其中加入从AllowBeanHolderd配置信息的功能即可?br /> 5、扩展DWR的DWRServletQ我们做一个SpringDWRServletQ原来的DWRServlet加蝲的是DefaultConfigurationQ我们的Serlvet加蝲我们自己的SpringConfiguration卛_?br /> 6、万事俱备,只欠东风啦。就是让Spring知道我们q了q些Q?br /> 在META-INF目录下(如果没有在src目录下创Z个)加入spring.handlers和spring.schemas两个文g?br /> spring.handlers中的内容Q?br /> http\: // www.devside.org/schema/spring/dwr=org.devside.core.support.dwr.DWRNamespaceHandler spring.schemas中的内容Q?br /> http\://www.devside.org/schema/spring/dwr.xsd=org/devside/core/support/dwr/dwr.xsd 注意不要写错字哦Q我一开始就写错一个字母,l果怎么调试都不能成功,q以为Spring2有问题呢?br /> ok了,下面我们可以写一个spring的配|文件来试试喽?br /> 下面提供两个源码包,一个是spring-dwr的源码,一个是hellosturts2Q一个struts2+spring2+hibernate3.2的例子,其中有用到spring-dwr的例子?br /> Z减小定wQ我把jar都去掉了Qlib目录下提供了一个列表,你可以自己去扄关的jar包?br />http://www.aygfsteel.com/Files/mstar/HelloStruts2.zip http://www.aygfsteel.com/Files/mstar/spring-dwr.zip ]]> dwr?-一个例?l二) http://www.aygfsteel.com/mstar/archive/2005/08/09/9674.html黑灵 黑灵 Tue, 09 Aug 2005 09:56:00 GMT http://www.aygfsteel.com/mstar/archive/2005/08/09/9674.html http://www.aygfsteel.com/mstar/comments/9674.html http://www.aygfsteel.com/mstar/archive/2005/08/09/9674.html#Feedback 5 http://www.aygfsteel.com/mstar/comments/commentRss/9674.html http://www.aygfsteel.com/mstar/services/trackbacks/9674.html 阅读全文 ]]> dwr?-一个例?l? http://www.aygfsteel.com/mstar/archive/2005/08/09/9673.html黑灵 黑灵 Tue, 09 Aug 2005 09:34:00 GMT http://www.aygfsteel.com/mstar/archive/2005/08/09/9673.html http://www.aygfsteel.com/mstar/comments/9673.html http://www.aygfsteel.com/mstar/archive/2005/08/09/9673.html#Feedback 5 http://www.aygfsteel.com/mstar/comments/commentRss/9673.html http://www.aygfsteel.com/mstar/services/trackbacks/9673.html 阅读全文 ]]> dwr?-一个例?/title> http://www.aygfsteel.com/mstar/archive/2005/08/08/9566.html黑灵 黑灵 Mon, 08 Aug 2005 05:58:00 GMT http://www.aygfsteel.com/mstar/archive/2005/08/08/9566.html http://www.aygfsteel.com/mstar/comments/9566.html http://www.aygfsteel.com/mstar/archive/2005/08/08/9566.html#Feedback 4 http://www.aygfsteel.com/mstar/comments/commentRss/9566.html http://www.aygfsteel.com/mstar/services/trackbacks/9566.html 阅读全文 ]]> dwr?/title> http://www.aygfsteel.com/mstar/archive/2005/08/08/9561.html黑灵 黑灵 Mon, 08 Aug 2005 05:26:00 GMT http://www.aygfsteel.com/mstar/archive/2005/08/08/9561.html http://www.aygfsteel.com/mstar/comments/9561.html http://www.aygfsteel.com/mstar/archive/2005/08/08/9561.html#Feedback 11 http://www.aygfsteel.com/mstar/comments/commentRss/9561.html http://www.aygfsteel.com/mstar/services/trackbacks/9561.html 最q?/SPAN>Ajax 比较火,全世界都在讨论。于是我也掺和掺和,直接?/SPAN>XMLHttpRequest Q现在的我还没有那个水^。用 Echo2 或?/SPAN>backbase Q又感觉那些U?/SPAN>Ajax ?/SPAN>framework 太重量了。我要的只是一些简单的应用而已。于是寻觅的重点攑֜了一些对 xmlhttpRequest q行轻量U包装的代码库上了。于是我扑ֈ?/SPAN>DWR Q?/SPAN>Direct Web Remoting Q?/SPAN>DWR 的口h AJAX and XMLHttpRequest made easy Qƈ且它也基本上做到了这一炏V它提供了一个友好的框架和一些很有用?/SPAN>JavaScript 库,可以让我用v Ajax 更容易些。详l的信息可以C们的|站 http://www.getahead.ltd.uk/dwr/ 。顺便在介绍一个网站吧Q?/SPAN>http://www.ajaxmatters.com q里也有很多关于 Ajax 的资源?/SPAN>
下面来简单介l一?/SPAN>DWR ?/SPAN>
其实在没?/SPAN>XMLHttpRequest ?/SPAN>DWR 有了,那时它用的是 IFrame Q效果很差,所以我看看了就没有?/SPAN>diao 它。现在的 DWR 主要?/SPAN>XMLHttpRequest Q当然也可以选者用 IFrame Q但是不推荐?/SPAN>
DWR 是个 open source software Q授权方式是 ASL version 2.0 的。现在网站上 examples and tutorials 做的也不错。我根据这些东西自׃做了一个应用,在本文的后面我会详细讲到?/SPAN>
现在 DWR 的最新版本是 1.0RC1 。在我的试用环境相还比较稳定,没有出现什么问题?/SPAN>
DWR 本n以一?/SPAN>dwr.jar ?/SPAN>jar 包存在,它的入口时一?/SPAN>Servlet Q?/SPAN>uk.ltd.getahead.dwr.DWRServlet Q所以要?/SPAN>web.xml 里配|一下就可以了。具体配|看q里 http://www.getahead.ltd.uk/dwr/intro.html 。比较简单?/SPAN>dwr 为我们提供了一?/SPAN>framework 帮我们很Ҏ的实?/SPAN>JavaScript ?/SPAN>java 之间的通信?/SPAN>
我还没有看过 dwr 的源码,具体他是怎么实现的我也不太清楚。但大致上肯定是通过 xmlhttprequest 来调用它?/SPAN>servlet 然后把数据用 xml 打包解包了。其实我觉得q部分到不是 dwr l我带来的最方便的地斏V最方便的地方应该是他的那些 js 的库?/SPAN>
所以下面我要介l一下它的两个重?/SPAN>js 对象?/SPAN>
DWREngine Q?/SPAN>engine.js 中)Q?/SPAN>DWRUtil (util.js ?/SPAN>) ?/SPAN>
DWREngine 中的Ҏ是基本上是关?/SPAN>XMLHttpRequest 的?/SPAN>
下面中介l一?/SPAN>
DWREngine.setErrorHandler(handler)
默认的错误处理时弹出一个对话框Q你可以通过q个Ҏ改变成你需要的表现形式?/SPAN>
DWREngine.setWarningHandler(handler)
改变默认的警告处理Ş?/FONT>
DWREngine.beginBatch()
Some Remote Function?/SPAN>
DWREngine.endBatch()
当你有几个远E调用要一赯行时Q就要用到这两个Ҏ?/SPAN>
如果不用q两个方法,你就会发C的远E调用ƈ不以你想象的序q行?/SPAN>
DWREngine 中还有一些其它的ҎQ我没有用过。你可以通过 dwr ?/SPAN>js-doc 来看。如果通过文档看不懂它是干什么用的,q js 源码Q源码的注释也是比较详细的?/SPAN>
DWRUtil 中也有一些很有用的方法。这些方法一般是~写 js 的辅助方法?/SPAN>
比如 setValue ?/SPAN>getValue 。大多数 html 标签?/SPAN>value 属性,q时你要获取或者设|它的值时q $(“someid?.value 可以了。但是有?/SPAN>html 标记是没?/SPAN>value 属性的Q它的值时在标{中间Q如 <span id=”span1?/st1:chmetcnv>>some value</span> q时你要取或讑֮的值的时候就?/SPAN>DWRUtil.setValue($(“span1? Q?/SPAN>someValue) 。这样你可以在客户端动态的表现一些数据了?/SPAN>
q有很多很好用的ҎQ?/SPAN>dwr 的例子中有一些说明,源码中的注释也比较详l?/SPAN>
Dwr ׃l到q里吧。下一,我做了个 table 的例子?BR>
]]>
վ֩ģ壺
|
|
¯ |
|
|
¤ |
Т |
|
|
ƾ |
|
|
|
|
ײ |
|
|
ǰ |
|
|
µ |
|
|
|
ˮ |
|
|
|
|
Ƥ |
|
°Ͷ |
|
Ҧ |
|
ν |
Ӷ |
|
± |
|
|