23456<" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

DWR源碼學習(一)

系統 2230 0
DWR一個外國人實現的很有前途的AJAX框架。
多余的話就不說了,請看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);//該方法對所有request路徑/dwr/*有效,在引用JS的時候,使用這個路徑執行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 ? .
這一部分經過了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方法內processor.handle(req, resp)這個方法如下:
?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);//這個方法是我們要關注的
? ??????????? }
?????。。。。。。。
? ????}
?iface.handle(req,?resp);//這個方法是我們要關注的,來自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自動生成javascript
?????????????String???path? = ?overridePath;
22 ? ???????? if ?(path? == ? null )
23 ? ????????{
24 ? ????????????path? = ?req.getContextPath(

DWR源碼學習(一)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日本不卡视频在线 | 狠狠干天天干 | 午夜欧美精品久久久久久久久 | 欧美精品亚洲精品日韩专区va | 亚洲高清视频在线播放 | 日韩男人天堂 | 四虎影视入口 | 爱操成人网 | 欧美在线一 | 亚洲国产精品久久久久久 | 欧美一级黄色毛片 | 一级女人18毛片免费 | 亚洲视频国产 | 国产91在线免费 | 深夜视频在线 | 国产第一页视频 | 国产成人精品免费久久久久 | 国产粉嫩白浆在线观看 | 操亚洲 | 老司机午夜精品视频在线观看免费 | 久久精品高清 | 2021最新国产成人精品免费 | 高清国产精品久久久久 | 久草在线视频免费资源观看 | 999热这里只有精品 999人在线精品播放视频 | 在线成人精品国产区免费 | 久久精品国产99精品最新 | 思思久久这里只精品99re66 | 国产精品日本一区二区在线看 | 性欧美视频 | 麻豆国产精品高中生视频 | 久久久久久久久久综合情日本 | 国产swag在线| 欧美日韩中文字幕在线视频 | 免费特黄一级欧美大片在线看 | 亚洲欧美不卡中文字幕 | 四虎影视免费看 | 夜夜操天天爽 | 中文国产成人精品久久一 | 天天曰天天干天天操 | 日本亚洲欧洲免费无码 |