- 浏览: 60257 次
- 性别:
- 来自: 深圳
文章分类
最新评论
Controller components of struts mainly include:
ActionServlet: as a center controller of struts framework.
RequestProcessor:as the request processor of every sub applicaiton model.
Action: handle a detailed transaction
main mission of them is:
1.receive the request of user.
2.execute relevant transaction logic by calling proper model compnent according to the request of user.
3.get the execution result of relevant transaction logic
4.choose the proper view component to user according to the execution result and the present situtation.
----------------------------------------------------------------------------------------------------------------------------------
ActionServlet:
There is just one instance of Actionservlet in the lifecycle.but can response many user request.
When launch the servlet container or send a request to the actionServlet for the first time to load the ActionServlet,in both these situations,servlet container will execute the init() method of ActionServlet immediately after the ActionServlet loaded to make sure that it have been initialized when handling the user request.
Init method have a flow:
1.call initInternal() method, in order to initialize the internal message resources like:notice,alert,error message which related to system log.
2.call initOther() method, in order to initialize the initial parameter in web.xml when load this servlet.like config,debug,detail and so on
3.call initServlet() method,load the URL mapping information of Actionservlet from web.xml,also can register the DTD files to validate the grammer of web.xml and struts-config.xml.
4.call initModuleConfig() method,load and analysis the default configuration files of sub application.Create the ModuleConfig object and store it to the ServletContext.
5.call initModuleMessageResources() method,load and initialize the message resource of the defalut sub application.Create the MessageResourcesobject and store it to the ServletContext.
6.call initModuleDataResources() method,load and initialize the data resources of the defalut sub application.This step will be cancelled if the <data-sources> element doesnot define in struts-config.xml
7.call initModulePlugins(),load and initialize all the plugins of the defalut sub application.
8.After the default application been successfully initialized,if there are some other sub applications,the flow will loop step 4 to step 7.to initialize other application separately.
When ActionServlet instance receive the HTTP request,it will call process() method of doGet or doPost to handle with this request.source code of method process in ActionServlet.
protected void process(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{ ModuleUtils.getInstance().selectModule(request.getServletContext); getRequestProcessor(getModuleConfig(request)).process(request,response);//go to RequestProcessor }
----------------------------------------------------------------------------------------------------------------------------------
From the source code of ActionSevlet,we can get that process method resend to RequestProcessor to deal with.ok,let's check what happened in process() method of RequestProcessor :
1.call processMultipart() method,if the HTTP request type is POST and contentType is start with "multipart/form-data",normal HttpServletRequest object will be repackaged for deal with the HTTP request of "multipart" type easily.If the HTTP request type is GET or the contentType is not "multipart",just returen the original HttpServletRequset Object.
2.call processPath() method,to achieve the URL path of request.this information can use for choosing the proper struts action component.
3.call processLocale() method,when the locale property of ControllerConfig is true,get the local information included in user request,then save the locale instance into session scope.
4.call processContent() method.get the contentType property of ControllerConfig,then set the document type and charset by calling response.setContentType(contentType).
5.call processNoCache() method,get the nocache propety of ControllerConfig,if the value is true,some specail head parameters like Pragma,Cache-Control and expires will be add into response result,in order to avoid the page store into the cache of client browser.
6.call processPreprocess() method,sub class can override this method to execute the pre-process request operation.
7.call processMapping() method,find the ActionMapping matching with request URL.if not exist,return error message.
8.call processRoles() method,judge if the security roles setted or not,if did,judge the current user has the neccssary roles by method isUserInRole(),else end the process flow and return error message.
9.call processActionForm() method,judget the ActionForm defined or not for ActionMapping firstly,if did,find ActionForm instance in ActionForm active scope.if not,create an instance,then save it in the proper scope with the key is the name property of ActionMapping.
10.call processPopulate() method,if the ActionForm has already been configured in ActionMapping,should call the reset() method of ActionForm,then put the form resource into ActionForm.
11.call processValidate() method,if the ActionForm has already been configured in ActionMapping,and the value of validate property is true,method validate() will be called.If the ActionErrors returned by this method including the ActionMessage,that means the form validation is failed,store the ActionErrors into the request scope,and redirect to the Web component pointed by input property of ActionMapping.it the validation is success,go to next step of this flow.
12.call processForward() method,judge if the forward property setted in ActionMapping or not,if did,call forward() method of RequestDispatcher,request handling flow is over. or go to next step.
13.call processInclude() method,judge if the include property setted in ActionMapping or not,if did,call include() method of RequestDispatcher,request handling flow is over. or go to next step.
14.call processActionCreate() method,firstly,check if the Action instance exist in Action cache,if not create a new Action instance,then save it in Action cache.
15.call processActionPerform() method,this method will call the execute() method of Action instance.this method surround by try/catch for catch the exception easily.
16.call processActionForward() method,transfer the ActionForward returned by exectue method of Action to Action.processActionForward() execute the redirect and send accroding to the request information of ActionForward.
----------------------------------------------------------------------------------------------------------------------------------
发表评论
-
unique foreign key mapping of hibernate example
2010-03-09 11:29 1280First the ddl language of the t ... -
spring transaction testing with hibernate
2010-01-12 17:20 888<beans xmlns="http://w ... -
Spring DAO with Jdbc and Hibernate
2010-01-07 17:34 887<beans xmlns="http://w ... -
Spring AOP config file and explaination
2010-01-06 14:50 1393I have give the comment in xml ... -
Ant
2010-01-04 18:34 825First,download a apache-ant-1.7 ... -
one-to-one mapping of hibernate
2009-10-13 18:00 1149first ,create two tables you wa ... -
Notes of hibernate about Xiaxin
2009-10-11 22:37 1132In order to test hibernate exam ... -
query by hibernate
2009-09-10 22:34 914This simple example is show the ... -
Knowledge of JSP for interview
2009-09-09 15:15 713Three compile command of JSP: @ ... -
Wiring collections , from java in action
2009-08-11 20:27 735The method implements: public ... -
The compare of Filter,CGLib and Dynamic proxy
2009-08-11 19:30 10971.If you want to use Filter for ... -
Call procedure by hibernate
2009-07-28 09:17 2246http://blog.csdn.net/wumingabc/ ...
相关推荐
Struts2是一个基于MVC(Model-View-Controller)设计模式的开源JavaEE框架,它极大地简化了企业级Web应用的开发。这个压缩包“struts-2.3.1”很可能包含了Struts2框架的源代码,版本为2.3.1。在这个版本中,我们可以...
Struts 是一个基于 Model-View-Controller (MVC) 设计模式的 Java Web 开发框架,它使得开发者能够更方便地构建动态网站应用程序。在"struts 附件上传 仿照163样式 实例"中,我们主要探讨的是如何使用 Struts 框架来...
org.apache.struts2.dispatcher Classes for action dispatching in Struts (the Controller part of MVC). org.apache.struts2.dispatcher.mapper org.apache.struts2.dispatcher.multipart Classes to help ...
Struts2是一个强大的Java web应用程序框架,它基于MVC(Model-View-Controller)设计模式,结合了Struts1和WebWork的优点。Struts2的工作原理深入探讨了其内部机制和核心组件,对于理解框架如何处理请求、路由到相应...
Struts2是一个强大的MVC(Model-View-Controller)框架,广泛应用于Java Web开发中,提供了丰富的功能,包括文件的上传和下载。在本项目中,我们关注的是如何使用Struts2来实现实时的文件交互操作,即文件的上传与...
Struts2是一款强大的Java web开发框架,它基于MVC(Model-View-Controller)设计模式,为开发者提供了构建可维护性、可扩展性极高的Web应用程序的工具和基础设施。本参考手册详细阐述了Struts2的核心特性、标签库、...
Struts 2是Java Web开发中的一个开源框架,它基于MVC(Model-View-Controller)设计模式,用于构建高效、可扩展且易于维护的企业级应用程序。Struts 2源代码的获取对于开发者来说非常重要,因为理解源码可以帮助我们...
2. **编写标签处理类**:创建一个继承自`org.apache.struts2.views.jsp.TagSupport`或`org.apache.struts2.components.UIBean`的Java类。这个类将处理标签的逻辑,包括获取和设置属性、计算分页参数等。 3. **标签...
在Struts中,Controller由ActionServlet实现,Model由业务逻辑组件(Business Logic Components)实现,View通常为JSP页面。Struts通过配置文件(struts-config.xml)来管理各个组件之间的交互,提供请求的转发和...
而EC标签(Extreme Components)则是Struts框架中的一个重要组成部分,为开发者提供了丰富的标签库来简化JSP页面的编写工作。本文将详细介绍Struts EC标签的使用方法及其特性。 #### 二、EC标签简介 EC标签是...
Struts2是一个基于MVC(Model-View-Controller)设计模式的开源Java Web框架,它在Web应用开发中被广泛使用。源代码是理解任何软件系统核心运作方式的关键,对于初学者来说,深入研究Struts2的源代码可以帮助他们更...
Struts2.0的工作原理是基于MVC(Model-View-Controller)架构模式,旨在简化Web应用开发,提高可维护性和可扩展性。 Struts2.0的核心设计与Struts1.x有很大的不同。它的主要工作流程如下: 1. **请求接收**:当一...
Struts 2是Java Web开发中的一个开源框架,它的出现是为了改进原先的Struts 1框架,提供更灵活、强大的MVC(Model-View-Controller)架构。在深入理解Struts 2.0.11.2源码之前,我们需要先了解这个版本的基本特性和...
Struts2.0是一个强大的Java Web开发框架,它极大地简化了MVC(Model-View-Controller)应用的构建。在Struts2中,标签库是其核心特性之一,提供了丰富的标签来帮助开发者更加便捷地创建动态网页。本文将深入探讨...
4. **Logging Components**: 在Struts开发环境中,日志是非常重要的工具,帮助开发者跟踪和调试代码。通常,Struts支持两种流行的日志框架:Commons Logging和Log4j。`commons-logging.jar`是Apache Commons Logging...
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/> ``` 这一行代码指定了Tiles的请求处理器类。 2. **Tiles插件配置**: ```xml <plug-in className="org.apache.struts.tiles....
Struts2 是一个基于MVC(Model-View-Controller)设计模式的Java Web框架,提供了丰富的特性和插件来简化这一过程。在本教程中,我们将深入探讨Struts2文件上传的实现方式以及相关知识点。 首先,理解文件上传的...