RequestProcessor's process()

  1. The processMultipart() method is called. If the HttpServletRequest method is a POST and the contentType of the request starts with multipart/form-data, the standard request object is wrapped with a special version from the Struts framework that deals exclusively with multipart requests. If the request method is a GET or the contentType is not multipart, the original request is returned. Unless your application supports uploading files, you don't need to worry about multipart functionality in Struts.

  2. The processPath() method is called to determine the path component from the URI for the request. Among other things, this information is used to select the appropriate Struts Action to invoke.

  3. The processLocale() method is called to determine the locale of the user making the request and to store a Locale object into the user's HttpSession object. The locale isn't always obtained into the user's session—it depends on the locale attribute in the controller configuration element. See Chapter 4 for more details on the attributes of the controller element.

  4. Determine the content type and optional encoding of the request by calling the processContent() method. The content type may be configured in the configuration settings and also overridden by the JSPs. The default content type is text/html.

  5. The processNoCache() method is called to determine whether the noCache attribute is set to true. If it is, add the proper header parameters in the response object to prevent the pages from being cached in the browser. The header parameters include Pragma, Cache-Control, and Expires.

  6. The processPreprocess() method is called next. It's a general-purpose preprocessing hook that, by default, just returns true. However, subclasses can override this method and perform conditional logic to decide whether to continue processing the request. Because this method gets called before an Action is invoked, this is a good place to validate whether the user contains a valid session. If this method returns true, processing of the request will continue. If it returns false, processing will stop. It's up to you to programmatically redirect or forward the request—the controller will assume that you are handling the request and will not send a response to the client.

  7. Determine the ActionMapping for the request using the path information by calling the processMapping( ) method. If a mapping can't be found using the path information, an error response will be returned to the client.

  8. Check to see if any security roles are configured for the Action by calling the processRoles( ) method. If there are roles configured, the isUserInRole() method is called on the request. If the user doesn't contain the necessary role, processing will end here and an appropriate error message will be returned to the client.

  9. Call the processActionForm() method to determine whether an ActionForm is configured for the ActionMapping. If an ActionForm has been configured for the mapping, an attempt will be made to find an existing instance in the appropriate scope. Once an ActionForm is either found or created, it is stored within the proper scope using a key that is configured in the name attribute for the Action element.

  10. The processPopulate() method is called next, and if an ActionForm is configured for the mapping, its properties are populated from the request parameter values. Before the properties are populated from the request, however, the reset() method is called on the ActionForm.

  11. The processValidate() method is called, and if an ActionForm has been configured and the validate attribute is set to true for the action element, the validate() method is called. If the validate() method detects errors, it will store an ActionErrors object into the request scope, and the request automatically will be forwarded to the resource specified by the input attribute for the action mapping. If no errors were detected from the validate() method or there was no ActionForm for the action mapping, processing of the request continues. You can configure the controller element to interpret the input attributes as defined forwards. See Chapter 4 for more information on this feature.

  12. Determine if a forward or an include attribute is configured for the action mapping. If so, call the forward() or include() method on the RequestDispatcher, depending on which one is configured. The processing of the request ends at this point if either one of these is configured. Otherwise, continue processing the request.

  13. Call the processActionCreate() method to create or acquire an Action instance to process the request. An Action cache will be checked to see if the Action instance already has been created. If so, that instance will be used to process the request. Otherwise, a new instance will be created and stored into the cache.

  14. Call the processActionPerform() method, which in turn calls the execute() method on the Action instance. The execute() call is wrapped with a try/catch block so that exceptions can be handled by the RequestProcessor.

  15. Call the processActionForward() method and pass it the ActionForward object returned from the execute() method. The processActionForward() method determines whether a redirect or a forward should occur by checking with the ActionForward object, which in turn depends on the redirect attribute in the forward element.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值