Please tell me what is the difference between ServletActionContext
and ServletContext
?
ServletContext
is shared among all the servlets and actions, while ServletActionContext
is specific to an action or is that also shared among all the actions?
The servletconfig object refers to the single servlet whereas servletcontext object refers to the whole web application. ServletConfig is implemented by the servlet container to initialize a single servlet using init(). That is, you can pass initialization parameters to the servlet using the web.
The ServletActionContext class provides methods to get HttpServletRequest, HttpServletResponse, ServletContext and HttpSession objects. It is a convenient class and prefered than ActionContext class.
ServletConfig is servlet specific. ServletContext is for whole application. Parameters of servletConfig are present as name-value pair in <init-param> inside <servlet>. Parameters of servletContext are present as name-value pair in <context-param> which is outside of <servlet> and inside <web-app>
The ServletContext object can be used to get configuration information from the web. xml file. The ServletContext object can be used to set, get or remove attribute from the web. xml file.
These are different things. ServletContext
is a servlet related, ActionContext
is Struts 2 action related, ServletActionContext
extends ActionContext
but in major it's an utility class.
If you want to know what is the actioncontext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With