第四部分 DWRServlet类分析
来源:互联网 发布:java公路自行车 编辑:程序博客网 时间:2024/05/21 17:30
org.directwebremoting.servlet.DwrServlet主要分为三部分,也就是三个主要方法:init;doGet;doPost;
1,init,初始化。
DWR对于Servelet容器内部设一个配置容器,该容器装载dwr映射相关信息。
{
super.init(servletConfig);
ServletContext servletContext = servletConfig.getServletContext();
try
{
// setupLogging() only needed for servlet logging if commons-logging is unavailable
// logStartup() just outputs some version numbers
日志初始化开始
StartupUtil.logStartup(servletConfig);
// create and setup a DefaultContainer
DWR对于Servelet容器内部设一个配置容器,该容器装载dwr隐射相关信息。
container = ContainerUtil.createAndSetupDefaultContainer(servletConfig);
StartupUtil.initContainerBeans(servletConfig, servletContext, container);
webContextBuilder = container.getBean(WebContextBuilder.class);
ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, this);
ContainerUtil.publishContainer(container, servletConfig);
ContainerUtil.configureContainerFully(container, servletConfig);
}
catch (ExceptionInInitializerError ex)
{
log.fatal("ExceptionInInitializerError. Nested exception:", ex.getException());
throw new ServletException(ex);
}
catch (Exception ex)
{
log.fatal("DwrServlet.init() failed", ex);
throw new ServletException(ex);
}
finally
{
if (webContextBuilder != null)
{
webContextBuilder.unset();
}
}
}
比较细致的环节:
init()调用
createAndSetupDefaultContainer()
调用
setupDefaultContainer(defaultContainer, servletConfig)
调用如下步骤
1)setupDefaults(container);
包括:
容器相关管理工具配置集,也就是要实现的一些接口。这种方式蛮好,当容器需要具备很多接口功能时,把这些接口全部做成隐射,并设置成可配置的实现
container.addImplementation(AccessControl.class, DefaultAccessControl.class);
// Mapping handlers to URLs,路径配置
createUrlMapping(container, "/index.html", IndexHandler.class, "indexHandlerUrl");
//读取servlet配置属性
2)setupFromServletConfig(container, servletConfig);
额外处理1)中多选类型
3)resolveMultipleImplementations(container, servletConfig);
里面使用了通用yui型压缩器
【使用 YUI Compressor 压缩 Javascript 和 CSS
工具下载: http://www.julienlecomte.net/yuicompressor/
英文介绍: http://com3.devnet.re3.yahoo.com/yui/compressor/
YUI Compressor是使用Java编写的工具,需要Java版本大于等于1.4。
工作原理简介:
主要是去掉冗余的空白,主要包括空格,换行符、制表符。
对于 Javascript,还采用缩短变量名的方法压缩文件,就是在保证代码正确性的情况下将变量名用只有1个字符的字符串代替,或者2个、3个字符,总之尽量短。
对于 CSS,还有采用优化0值属性值的表示,优化颜色值的方法压缩文件。
CSS的优化比 CSSTidy 功能弱。CSSTidy还能支持一些相关属性的合并。】
//工具配置集 加载,显现,检查
4)container.setupFinished();
容器内容bean初始化 ,包括系统默认???
initContainerBeans
2,doGet
实际调用doPost,看到这里最好温习下servlet的doGet方法和doPost的区别
{
doPost(req, resp);
}
3,doPost
在工程中,有个样例Dynamically Text,地址是http://localhost:5050/dwr/simpletext/index.html,当点击按钮时,实际上就是触发了org.directwebremoting.servlet.DwrServlet的下面的方法。
{
try
{
webContextBuilder.set(request, response, getServletConfig(), getServletContext(), container);
UrlProcessor processor = container.getBean(UrlProcessor.class);
processor.handle(request, response);
}
finally
{
webContextBuilder.unset();
}
}
- 第四部分 DWRServlet类分析
- 数据文件结构分析——第四部分
- 第四部分 linux led驱动代码分析
- 第四部分 类与对象
- DWR监听器类无法加载。DwrServlet 无法加载
- XBRL流行工具分析与比较-第四部分
- gcc源代码分析,expand_call ()函数第四部分,emit_call_1 ()函数
- 【Apollo源码分析】系列的第四部分【decision】
- 【Linux探索之旅】第四部分第四课:分析网络,隔离防火
- Linux探索之旅 | 第四部分第四课:分析网络,隔离防火
- org.directwebremoting.servlet.DwrServlet
- DWRServlet dwr相关原理
- 40-总结-【cartographer源码分析】系列的第四部分【io源码分析】
- refactoring Patterns:第四部分
- 第四部分 方法---------------
- 第四部分 方法2---------------
- 第四部分 方法3---------------
- 第四部分 方法4---------------
- 第一部分 DWR是什么,如何使用
- 欢迎大家讨论“趁着年轻树立目标”
- 第二部分 下载源码,做好准备
- vc学习笔记--控件篇(一)
- 第三部分 DWR的技术基石-无刷新访问服务器
- 第四部分 DWRServlet类分析
- 第五部分 包拆解 1)org.directwebremoting包
- 第五部分 包拆解 2)org.directwebremoting.bayeux包
- 第五部分 包拆解 3)org.directwebremoting.convert包
- 提问:初学JAVA的疑问关于indexOf的用法
- 第五部分 包拆解 4)org.directwebremoting.create包
- 第六部分 DWR原理
- vc学习笔记--控件篇(二)
- 分类广告第一站 Craiglist 的成功案例