struts源码学习5
来源:互联网 发布:ubuntu修改登录界面 编辑:程序博客网 时间:2024/06/05 08:05
ActionServlet.init()
1、initModuleForwards
配置全局forwards
protected void initModuleForwards(ModuleConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' forwards"); } // Process forwards extensions. //获取到ForwardConfigs ForwardConfig[] forwards = config.findForwardConfigs(); for (int i = 0; i < forwards.length; i++) { ForwardConfig forward = forwards[i]; //处理继承,实际上需要配置extends才有效,但是已被dtd限制,和前面的formbean一样 processForwardExtension(forward, config, null); } for (int i = 0; i < forwards.length; i++) { ForwardConfig forward = forwards[i]; //必须配置path,否则抛异常 // Verify that required fields are all present for the forward if (forward.getPath() == null) { handleValueRequiredException("path", forward.getName(), "global forward"); } } }2、initModuleExceptionConfigs
配置全局异常处理
protected void initModuleExceptionConfigs(ModuleConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' forwards"); } //异常处理配置 // Process exception config extensions. ExceptionConfig[] exceptions = config.findExceptionConfigs(); for (int i = 0; i < exceptions.length; i++) { ExceptionConfig exception = exceptions[i]; processExceptionExtension(exception, config, null); } for (int i = 0; i < exceptions.length; i++) { ExceptionConfig exception = exceptions[i];<span style="white-space:pre"></span>//必须配置key // Verify that required fields are all present for the config if (exception.getKey() == null) { handleValueRequiredException("key", exception.getType(), "global exception config"); } } }
3、initModuleActions
protected void initModuleActions(ModuleConfig config) throws ServletException { if (log.isDebugEnabled()) { log.debug("Initializing module path '" + config.getPrefix() + "' action configs"); } // Process ActionConfig extensions. ActionConfig[] actionConfigs = config.findActionConfigs(); for (int i = 0; i < actionConfigs.length; i++) { ActionConfig actionConfig = actionConfigs[i]; processActionConfigExtension(actionConfig, config); } for (int i = 0; i < actionConfigs.length; i++) { ActionConfig actionConfig = actionConfigs[i]; // Verify that required fields are all present for the forward // configs //forwards处理 ForwardConfig[] forwards = actionConfig.findForwardConfigs(); for (int j = 0; j < forwards.length; j++) { ForwardConfig forward = forwards[j]; if (forward.getPath() == null) { handleValueRequiredException("path", forward.getName(), "action forward"); } } //异常处理 // ... and the exception configs ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs(); for (int j = 0; j < exceptions.length; j++) { ExceptionConfig exception = exceptions[j]; if (exception.getKey() == null) { handleValueRequiredException("key", exception.getType(), "action exception config"); } } } }4、moduleConfig.freeze
该方法调用moduleConfig中所有config的freeze方法(比如actionConfig,controllerConfig等等)
调用该方法之后,所有的Config均不能调用setXX方法,一旦调用,将抛出异常
5、init其余代码
在拿到其它ServletConfig参数后,遍历
Enumeration names = getServletConfig().getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement();<span style="white-space:pre"></span>//如果name已config开头,则认为是一个新的ActionServlet配置,这个ActionServlet配置是带prefix的。之前的配置中是没有prefix的 if (!name.startsWith(configPrefix)) { continue; } String prefix = name.substring(configPrefixLength); moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name)); initModuleMessageResources(moduleConfig); initModulePlugIns(moduleConfig); initModuleFormBeans(moduleConfig); initModuleForwards(moduleConfig); initModuleExceptionConfigs(moduleConfig); initModuleActions(moduleConfig); moduleConfig.freeze(); } this.initModulePrefixes(this.getServletContext()); this.destroyConfigDigester();
0 0
- struts源码学习5
- Struts 源码学习笔记
- Struts 源码学习笔记
- Struts源码的切片学习之Struts的初始化
- Struts源码学习 — 初始化ModuleConfig
- Struts源码学习 — 初始化ModuleConfig (1)
- Struts 源码学习之ActionServlet ( 一)
- Struts源码学习之ActionServlet(二)
- Struts源码学习之ActionServlet(一)
- Struts源码学习之ActionServlet(一)
- Struts源码学习之ActionServlet(一)
- Struts 源码学习之ActionServlet ( 一)
- Struts 源码学习之ActionServlet ( 二)
- Struts源码学习之ActionServlet(一)
- struts学习笔记5
- Struts学习笔记5
- Struts 源码学习笔记--在web.xml文件中的初始化
- Struts的资源文件时如何初始化的--struts源码学习
- DFS
- POJ1789&ZOJ2158--Truck History【最小生成树变形】
- 树莓派学习笔记——使用标准PC104键盘
- String s = new String("abc");创建了几个String对象
- android之LinearLayout中android:layout_weight属性理解
- struts源码学习5
- 设计模式实现(十七)---单例模式(SingleTon)
- 指出下面代码的输出,并解释为什么(指针问题)
- hdu 1799 循环多少次?
- linux下多线程编程
- 关于jCrop图片拉伸的问题
- ajax+spring文件上传
- poj 2109 Power of Cryptography(暴力枚举)
- 简易秒表Android源代码