开发者

Exact Meaning of Struts Interceptor

开发者 https://www.devze.com 2023-01-30 02:38 出处:网络
Can anyone tell me, what is exact meaning of INTERCEPTOR in Struts 2 Fram开发者_JAVA百科ework? Could you please give me some simple example with Struts interceptor?

Can anyone tell me, what is exact meaning of INTERCEPTOR in Struts 2 Fram开发者_JAVA百科ework?

Could you please give me some simple example with Struts interceptor?

Thanks IN Advance!


Think of what the Interceptors is to Struts as Filters is to Servlets. When you request a Struts Action, The Struts Framework sends a request to the called action, but before the action is executed, the invocation can be interpreted by interceptors. Once the're done, the request is passed (as servlet calls it, filtered) to the action.

The reason for interceptors is, you want to do some pre-conditional / post-conditional checking to be sent to the action / returned by the action. A simple example will be File upload. When you send a file to an action in Struts, you can have an interceptor that is used as a pre-condition validator (e.g, the file size must be 5210 bytes exactly = 5MB). If successful, it filters the request to the action (that was called).

I've never used Struts 2 but there's a Wiki on Interceptors at Apache site.


Well Why Interceptors or whats there relevancy in Struts2..These are a part of moduler approach where you have some predefined modules as per the need and you can plug them or unplug them as per your need.

Struts2 is a web frame work and in order to process the request it has to undergo certain steps which are common for every request process cycle so Struts2 develoers have created these module which are indentiifed as common module which every request in web application needs

like when you submit the data we need to conver the data to appropriate form this is struts is being done by the Interceptors if some validation is needed how to do it is being done by interceptors they are somethig which are like modules or plugin plug which ever you want to use and unplug them which you don't do..

in shorter terem these Interceptors is doing all necessary work for you so that you can concentrate on ur business logic

0

精彩评论

暂无评论...
验证码 换一张
取 消