java - Whats the difference between ActionContext,ServletContext and ServletActionContext? -
in java ee, use actioncontext
,servletcontext
, servletactioncontext
, have similar name, don't know difference between them.
i know servletactioncontext
inherit actioncontext
. can explain them?
there have many difference between them.
servletcontext
from servletcontext
's package(javax.servlet.servletcontext
) can know standard javaee webapplication class library.
servletcontext provides standard servlet run-time environment. methods of servlet communicate web container.
public interface servletcontext { // returns url prefix servletcontext. public string getservletcontextname(); //returns context-path web-application. public string getcontextpath(); //returns servletcontext uri. public servletcontext getcontext(string uri); //returns real file path given uri. public string getrealpath(string uri); public requestdispatcher getnameddispatcher(string servletname); public requestdispatcher getrequestdispatcher(string uri);
servletcontext included in servletconfig, , servletconfig read servlet or filter's init()
method:
servletconfig.getservletcontext() filterconfig.getservletcontext()
actioncontext
comes struts, @ first comes struts1 , struts2 different.
from struts1:
servlet
(servlet org.apache.struts.action.actionservlet) handle *.do
action.
from struts2:
filter
(org.apache.struts2.dispatcher.filterdispatcher) handle request.
because struts1 belongs servlet scope. struts1 action's servlet.
struts2 action normal java bean, out of servlet limitations.
actioncontext makes lost web environment after strtus2 action out of stand servlet framework.
the actioncontext main function:
- provide web context.
- solve thread security issue.
- solve incompatibility problem other framework(such as: weblogic))
servletactioncontext
as say, servletactioncontext actioncontext's subclass. functions starting @ actioncontext, , encapsulate methods, make more simple , intuitive.
we can study source code:
public class servletactioncontext extends actioncontext implements strutsstatics { //http servlet request public static void setrequest(httpservletrequest request) { actioncontext.getcontext().put(http_request, request); } public static httpservletrequest getrequest() { return (httpservletrequest) actioncontext.getcontext().get(http_request); } //http servlet response public static void setresponse(httpservletresponse response) { actioncontext.getcontext().put(http_response, response); } public static httpservletresponse getresponse() { return (httpservletresponse) actioncontext.getcontext().get(http_response); } //servlet context. public static servletcontext getservletcontext() { return (servletcontext) actioncontext.getcontext().get(servlet_context); } public static void setservletcontext(servletcontext servletcontext) { actioncontext.getcontext().put(servlet_context, servletcontext); }
from above can know servletactioncontext extends actioncontext.
Comments
Post a Comment