<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    javajohn

    金色年華

    DWR源碼學(xué)習(xí)(一)

    DWR一個(gè)外國人實(shí)現(xiàn)的很有前途的AJAX框架。
    多余的話就不說了,請(qǐng)看DWR的例子程序:
    web.xml
    ?1<?xml?version="1.0"?encoding="ISO-8859-1"?>
    ?2<!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"?"http://java.sun.com/dtd/web-app_2_3.dtd">
    ?3
    ?4<web-app?id="dwr">
    ?5
    ?6??<display-name>DWR?(Direct?Web?Remoting)</display-name>
    ?7??<description>A?demo?of?how?to?call?Java?on?the?server?directly?from?Javascript?on?the?client</description>
    ?8
    ?9??<servlet>
    10????<servlet-name>dwr-invoker</servlet-name>
    11????<display-name>DWR?Servlet</display-name>
    12????<description>Direct?Web?Remoter?Servlet</description>
    13????<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
    14????<!--
    15????<init-param>
    16??????<param-name>config</param-name>
    17??????<param-value>WEB-INF/dwr.xml</param-value>
    18????</init-param>
    19????-->
    20????<init-param>
    21??????<param-name>debug</param-name>
    22??????<param-value>true</param-value>
    23????</init-param>
    24????<init-param>
    25??????<param-name>scriptCompressed</param-name>
    26??????<param-value>false</param-value>
    27????</init-param>
    28????<load-on-startup>1</load-on-startup>
    29??</servlet>
    30
    31??<servlet-mapping>
    32????<servlet-name>dwr-invoker</servlet-name>
    33????<url-pattern>/dwr/*</url-pattern>
    34??</servlet-mapping>
    35
    36</web-app>
    servlet(uk.ltd.getahead.dwr.DWRServlet)里:
    ?1?????protected?void?doPost(HttpServletRequest?req,?HttpServletResponse?resp)?throws?IOException,?ServletException
    ?2?????{
    ?3?????????try
    ?4?????????{
    ?5?????????????builder.set(req,?resp,?getServletConfig(),?getServletContext(),?container);
    ?6?????????????ServletLoggingOutput.setExecutionContext(this);
    ?7?
    ?8?????????????processor.handle(req,?resp);//該方法對(duì)所有request路徑/dwr/*有效,在引用JS的時(shí)候,使用這個(gè)路徑執(zhí)行dwr生成的javascript代碼

    ????finally
    11?????????{
    12?????????????builder.unset();
    13?????????????ServletLoggingOutput.unsetExecutionContext();
    14?????????}
    15?????}

    index.html
    ?1?<?xml?version="1.0"?encoding="ISO-8859-1"??>
    ?2?<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.1//EN"?"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    ?3?<html?xmlns="http://www.w3.org/1999/xhtml">
    ?4?<head>
    ?5???<title>DWR?-?Test?Home</title>
    ?6???<script?type='text/javascript'?src='dwr/interface/Test.js'></script>
    ?7???<script?type='text/javascript'?src='dwr/engine.js'></script>
    ?8???<script?type='text/javascript'?src='dwr/util.js'></script>
    ?9???<script>
    10?????function?init()?{
    11???????//?This?turns?off?the?no-javascript?message
    12???????document.getElementById("start").style.display?=?"none";
    13???????//?This?checks?for?file:?URLs?and?loading?problems
    14???????if?(window.DWREngine?==?null?||?window.DWRUtil?==?null)?{
    15?????????document.getElementById("file").style.display?=?"block";
    16?????????return;
    17???????}
    18???????//?DWR?setup
    19???????DWREngine.setErrorHandler(function(message)?{?alert(message);?});
    20???????DWREngine.setWarningHandler(function(message)?{?alert(message);?});
    21???????DWRUtil.useLoadingMessage();
    22???????//?Turn?on?the?generic?error?div
    23???????$("error").style.display?=?"block";
    24???????//?Load?a?message?from?the?server
    25???????Test.getInsert(load);
    26?????}
    27?
    28?????function?load(data)?{
    29???????$("error").style.display?=?"none";
    30???????DWRUtil.setValue("reply",?data);
    31???????$("reply").style.display?=?"block";
    32?????}
    33???</script>
    34?</head>
    35?
    36?<body?onload="init()">
    37?.
    這一部分經(jīng)過了SERVLET處理:
    ??<script?type='text/javascript'?src='dwr/interface/Test.js'></script>
    ??
    <script?type='text/javascript'?src='dwr/engine.js'></script>
    ??
    <script?type='text/javascript'?src='dwr/util.js'></script>
    dwrservlet.doPost方法內(nèi)processor.handle(req, resp)這個(gè)方法如下:
    ?1?????public?void?handle(HttpServletRequest?req,?HttpServletResponse?resp)?throws?IOException,?ServletException
    ?2?????{
    ?3?????????String?pathInfo?=?req.getPathInfo();
    ?4?????????String?servletPath?=?req.getServletPath();
    ?5?
    ?6?????????if?(nullPathInfoWorkaround?&&?pathInfo?==?null)
    ?7?????????{
    ?8?????????????pathInfo?=?req.getServletPath();
    ?9?????????????servletPath?=?HtmlConstants.PATH_ROOT;
    10?????????????log.debug("Default?servlet?suspected.?pathInfo="?+?pathInfo?+?";?contextPath="?+?req.getContextPath()?+?";?servletPath="?+?servletPath);?//$NON-NLS-1$?//$NON-NLS-2$?//$NON-NLS-3$
    11?????????}
    12?
    13?????????if?(pathInfo?==?null?||
    14?????????????pathInfo.length()?==?0?||
    15?????????????pathInfo.equals(HtmlConstants.PATH_ROOT))
    16?????????{
    17?????????????resp.sendRedirect(req.getContextPath()?+?servletPath?+?HtmlConstants.FILE_INDEX);
    18?????????}
    19?????????else?if?(pathInfo.startsWith(HtmlConstants.FILE_INDEX))
    20?????????{
    21?????????????index.handle(req,?resp);
    22?????????}
    23?????????else?if?(pathInfo.startsWith(HtmlConstants.PATH_TEST))
    24?????????{
    25?????????????test.handle(req,?resp);
    26?????????}
    27?????????else?if?(pathInfo.startsWith(HtmlConstants.PATH_INTERFACE))
    28?????????{
    29?????????????iface.handle(req,?resp);//這個(gè)方法是我們要關(guān)注的
    ???????????? }
    ?????。。。。。。。
    ?????}
    ?iface.handle(req,?resp);//這個(gè)方法是我們要關(guān)注的,來自DefaultInterfaceProcessor
    ?1?????public?void?handle(HttpServletRequest?req,?HttpServletResponse?resp)?throws?ServletException,?IOException
    ?2?????{
    ?3?????????String?pathinfo?=?req.getPathInfo();
    ?4?????????String?servletpath?=?req.getServletPath();
    ?5?????????if?(pathinfo?==?null)
    ?6?????????{
    ?7?????????????pathinfo?=?req.getServletPath();
    ?8?????????????servletpath?=?HtmlConstants.PATH_ROOT;
    ?9?????????}
    10?????????String?scriptname?=?pathinfo;
    11?????????scriptname?=?LocalUtil.replace(scriptname,?HtmlConstants.PATH_INTERFACE,?HtmlConstants.BLANK);
    12?????????scriptname?=?LocalUtil.replace(scriptname,?HtmlConstants.EXTENSION_JS,?HtmlConstants.BLANK);
    13?????????Creator?creator?=?creatorManager.getCreator(scriptname);
    14?
    15?????????//resp.setContentType("text/javascript");
    16?????????PrintWriter?out?=?resp.getWriter();
    17?????????out.println();
    18?
    19?????????out.println("function?"?+?scriptname?+?"()?{?}");?//從這里開始DWR自動(dòng)生成javascript
    ?????????????String???path?=?overridePath;
    22?????????if?(path?==?null)
    23?????????{
    24?????????????path?=?req.getContextPath()?+?servletpath;
    25?????????}
    26?????????out.println(scriptname?+?"._path?=?'"?+?path?+?"';");?//$NON-NLS-1$?//$NON-NLS-2$
    27?
    28?????????Method[]?methods?=?creator.getType().getMethods();
    29?????????for?(int?i?=?0;?i?<?methods.length;?i++)
    30?????????{
    31?????????????Method?method?=?methods[i];
    32?????????????String?methodName?=?method.getName();
    33?
    34?????????????//?We?don't?need?to?check?accessControl.getReasonToNotExecute()
    35?????????????//?because?the?checks?are?made?by?the?doExec?method,?but?we?do?check
    36?????????????//?if?we?can?display?it
    37?????????????String?reason?=?accessControl.getReasonToNotDisplay(req,?creator,?scriptname,?method);
    38?????????????if?(reason?!=?null?&&?!allowImpossibleTests)
    39?????????????{
    40?????????????????continue;
    41?????????????}
    42?
    43?????????????//?Is?it?on?the?list?of?banned?names
    44?????????????if?(jsutil.isReservedWord(methodName))
    45?????????????{
    46?????????????????continue;
    47?????????????}
    48?
    49?????????????out.print('\n');
    50?????????????out.print(scriptname?+?'.'?+?methodName?+?"?=?function(");?//$NON-NLS-1$
    51?????????????Class[]?paramTypes?=?method.getParameterTypes();
    52?????????????for?(int?j?=?0;?j?<?paramTypes.length;?j++)
    53?????????????{
    54?????????????????if?(!LocalUtil.isServletClass(paramTypes[j]))
    55?????????????????{
    56?????????????????????out.print("p"?+?j?+?",?");?//$NON-NLS-1$?//$NON-NLS-2$
    57?????????????????}
    58?????????????}
    59?????????????out.println("callback)?{");?//$NON-NLS-1$
    60?
    61?????????????out.print("????DWREngine._execute("?+?scriptname?+?"._path,?'"?+?scriptname?+?"',?'"?+?methodName?+?"\',?");?//實(shí)現(xiàn)javascript調(diào)用java內(nèi)的方法
    ?????????????????for?(int?j?=?0;?j?<?paramTypes.length;?j++)
    63?????????????{
    64?????????????????if?(LocalUtil.isServletClass(paramTypes[j]))
    65?????????????????{
    66?????????????????????out.print("false,?");?//$NON-NLS-1$
    67?????????????????}
    68?????????????????else
    69?????????????????{
    70?????????????????????out.print("p"?+?j?+?",?");?//$NON-NLS-1$?//$NON-NLS-2$
    71?????????????????}
    72?????????????}
    73?????????????out.println("callback);");?//$NON-NLS-1$
    74?
    75?????????????out.println('}');
    76?????????}
    77?
    78?????????out.flush();
    79?????}
    DWR例子程序下載地址:http://www.tkk7.com/Files/javajohn/dwr.rar
    (待續(xù))

    posted on 2006-05-27 19:23 javajohn 閱讀(5545) 評(píng)論(13)  編輯  收藏 所屬分類: AJAX

    Feedback

    # 求助 2006-06-11 16:21 Aivon

    近來才開始接觸AJAX
    想在一個(gè)大作業(yè)中使用DWR
    在網(wǎng)上找了很多配置教程
    但我在自己機(jī)上老是測(cè)試不成功
    郁悶中……
    近來趕大作業(yè),就要考試了,還請(qǐng)大哥能幫幫忙,給點(diǎn)提示
    小弟的QQ是:4034947  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-06-12 08:51 javajohn

    mail to me
    DWR的配置例子在下載的代碼里有demo  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-06-13 01:05 Aivon

    找不到你的email阿...

    我在官方網(wǎng)站下在的demo運(yùn)行時(shí)顯示:
    Missing DWR Javascript Functions

    自己按照網(wǎng)上的教程進(jìn)行配置
    也顯示js文件錯(cuò)誤

    能否給我一份你使用正常的代碼?
    我的email是:aivon@163.com
    謝謝了  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-06-13 09:20 javajohn

    我的mail:thesecondbull@yahoo.com.cn
    DWR代碼下載地址http://www.tkk7.com/Files/javajohn/dwr.rar
    下載的文件后綴更名為.war  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-06-13 10:30 Aivon

    還是出現(xiàn)以下問題:
    Missing DWR Javascript Functions
    This is a fairly advanced page that tests DWR to check that everything is setup properly for you.

    It appears that you may be attempting to run DWR outside a servlet container (possibly using a file: URL). We think this because this page has missing Javascript functions that should have been produced by DWR. To fix the problem please use DWR from within a servlet container.

    If this is not the cause of the problem, please report it to the DWR mailing list, including your browser, server, OS configuration and any error messages that appeared either in the browser (including the Javascript console if one exists) and the server console log.

    DWR is testing installation ...
    This is a fairly advanced page that tests DWR. If you can see this message for a prolonged period of time then you should check the following:

    Can you see the test pages?
    If not it is likely that DWR has not deployed in your web server properly; Check the web server console and log files for error messages.
    If you can see the test pages then DWR is loaded but is something is preventing DWR working. Check your browser Javascript console for error messages, or see the main DWR website for more information.
    If none of these steps fixes the error, please report it to the DWR mailing list, including your browser, server, OS configuration and any error messages that appeared either in the browser (including the Javascript console if one exists) and the server console log.

    For general information about DWR see:

    不解~~~  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-06-13 10:59 javajohn

    @Aivon
    說一下你的JDK和TOMCAT的版本,JDK如果為1.5以上TOMCAT需要5.5以上的版本  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-06-13 12:27 Aivon

    哈,原來是tomcat的版本問題
    換了5.5的就OK了

    謝謝了~~~  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-07-10 09:43 snackok

    下載了,提示Test對(duì)象不存在,發(fā)現(xiàn)dwr/interface/目錄下缺少test.js  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-07-10 15:11 javajohn

    test.js是由DWR自動(dòng)生成的,不再是我們以前開發(fā)時(shí)的那種概念上的js文件了.如果不清楚請(qǐng)?jiān)僭敿?xì)閱讀我BLOG里的另一篇《dwr源碼學(xué)習(xí)函數(shù)調(diào)用篇》  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-07-25 14:46 Sandy


    可以跟我講下DWR2.0中JAVA調(diào)用JS嗎?  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-08-20 09:31 東北小白

    不錯(cuò)哈哈,謝謝摟住  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-09-14 14:42 vircomagice

    摟主有沒有DWR的源碼和發(fā)行包啊,我這里下載不了https的連接,很郁悶。。。
    如果有的話,能不能發(fā)我一封啊
    vircomagice@yahoo.com.cn  回復(fù)  更多評(píng)論   

    # re: DWR源碼學(xué)習(xí)(一) 2006-09-14 19:05

    @vircomagice
    發(fā)行包到處都有啊,你到www.springside.org.cn下載不就行了  回復(fù)  更多評(píng)論   



    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    My Links

    Blog Stats

    常用鏈接

    留言簿(7)

    隨筆分類(36)

    隨筆檔案(39)

    classmate

    good blog

    企業(yè)管理網(wǎng)站

    好友

    站點(diǎn)收藏

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 免费观看美女裸体网站| 免费观看久久精彩视频| 精品亚洲国产成人av| 亚洲综合精品成人| 亚洲熟妇无码av另类vr影视| 国产成人精品日本亚洲专| 亚洲av无码片区一区二区三区| 亚洲成人黄色在线| 亚洲综合久久一本伊伊区| 最新国产成人亚洲精品影院| 亚洲av片不卡无码久久| 亚洲天堂免费在线| 亚洲国产精品日韩av不卡在线 | 国产va精品免费观看| 免费a级毛片无码a∨蜜芽试看 | 一区二区三区免费精品视频 | 亚洲a∨无码男人的天堂| 在线观看亚洲AV日韩A∨| 蜜芽亚洲av无码一区二区三区| 国产亚洲精品91| 中文毛片无遮挡高清免费| 免费网站观看WWW在线观看| 18级成人毛片免费观看| 最近免费中文字幕大全视频| 国产精品久久香蕉免费播放| 亚洲国产中文字幕在线观看 | 免费黄色大片网站| 亚洲精品高清在线| 亚洲妇熟XXXX妇色黄| 亚洲国产精品美女| 久久久久久久久无码精品亚洲日韩| 天堂亚洲免费视频| 男人进去女人爽免费视频国产| aⅴ免费在线观看| 国产精品高清全国免费观看| 亚洲乱码日产一区三区| 亚洲国产成人久久99精品| MM1313亚洲精品无码久久| 花蝴蝶免费视频在线观看高清版| AV无码免费永久在线观看| 免费国产成人午夜私人影视 |