ActionContext,ServletContext和ServletActionContext有什么区别?
来源:互联网 发布:苹果电脑看图软件 编辑:程序博客网 时间:2024/05/22 12:28
他们之间有很多区别。
ServletContext
从ServletContext
的包( javax.servlet.ServletContext
)我们可以知道它是标准的JavaEE WebApplication类库。
ServletContext提供了标准的Servlet运行时环境。 实际上是servlet与web容器进行通信的一些方法。
public interface ServletContext { // Returns the URL prefix for the ServletContext. public String getServletContextName(); //Returns the context-path for the web-application. public String getContextPath(); //Returns the ServletContext for the uri. public ServletContext getContext(String uri); //Returns the real file path for the given uri. public String getRealPath(String uri); public RequestDispatcher getNamedDispatcher(String servletName); public RequestDispatcher getRequestDispatcher(String uri);
ServletContext包含在ServletConfig中,ServletConfig通常从servlet或filter的init()
方法读取:
servletConfig.getServletContext() filterConfig.getServletContext()
ActionContext
来自Struts,但是起初来自Struts1和Struts2,它们是不同的。
从Struts1:
一个servlet
(servlet org.apache.struts.action.ActionServlet)处理所有的*.do
动作。
从Struts2: filter
(org.apache.struts2.dispatcher.FilterDispatcher)处理所有请求。
因为struts1属于servlet范围。 struts1动作本质上是servlet。
struts2动作是普通的Java bean,出了servlet限制。
在strtus2动作出来之后,ActionContext构成了丢失的WEB环境。
ActionContext主要功能:
- 提供WEB上下文。
- 解决线程安全问题。
- 解决与其他Framework不兼容的问题(如:webLogic))
ServletActionContext
正如你所说,ServletActionContext是ActionContext的子类。 它的功能是从ActionContext开始,封装方法,使其更加简单直观。
我们还可以研究其源代码:
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); }
从上面我们可以知道ServletActionContext扩展了ActionContext。
他们之间有很多区别。
ServletContext
从ServletContext
的包( javax.servlet.ServletContext
)我们可以知道它是标准的JavaEE WebApplication类库。
ServletContext提供了标准的Servlet运行时环境。 实际上是servlet与web容器进行通信的一些方法。
public interface ServletContext { // Returns the URL prefix for the ServletContext. public String getServletContextName(); //Returns the context-path for the web-application. public String getContextPath(); //Returns the ServletContext for the uri. public ServletContext getContext(String uri); //Returns the real file path for the given uri. public String getRealPath(String uri); public RequestDispatcher getNamedDispatcher(String servletName); public RequestDispatcher getRequestDispatcher(String uri);
ServletContext包含在ServletConfig中,ServletConfig通常从servlet或filter的init()
方法读取:
servletConfig.getServletContext() filterConfig.getServletContext()
ActionContext
来自Struts,但是起初来自Struts1和Struts2,它们是不同的。
从Struts1:
一个servlet
(servlet org.apache.struts.action.ActionServlet)处理所有的*.do
动作。
从Struts2: filter
(org.apache.struts2.dispatcher.FilterDispatcher)处理所有请求。
因为struts1属于servlet范围。 struts1动作本质上是servlet。
struts2动作是普通的Java bean,出了servlet限制。
在strtus2动作出来之后,ActionContext构成了丢失的WEB环境。
ActionContext主要功能:
- 提供WEB上下文。
- 解决线程安全问题。
- 解决与其他Framework不兼容的问题(如:webLogic))
ServletActionContext
正如你所说,ServletActionContext是ActionContext的子类。 它的功能是从ActionContext开始,封装方法,使其更加简单直观。
我们还可以研究其源代码:
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); }
从上面我们可以知道ServletActionContext扩展了ActionContext。
- ActionContext,ServletContext和ServletActionContext有什么区别?
- ServletContext和Struts2中的ActionContext/ServletActionContext区别
- ActionContext 、ServletContext 和 ServletActionContext 的区别
- ServletContext,ActionContext,ServletActionContext的区别
- ServletContext,ActionContext,ServletActionContext的区别
- ServletContext,ActionContext,ServletActionContext 的区别
- ServletContext,ActionContext和ServletActionContext比较
- struts2中 ServletActionContext、ActionContext和ServletContext三者的区别
- ActionContext 和 ServletActionContext区别
- ActionContext和ServletActionContext区别
- ActionContext和ServletActionContext区别
- ActionContext和ServletActionContext区别
- ActionContext和ServletActionContext区别
- ActionContext和ServletActionContext区别
- ActionContext和ServletActionContext区别
- ServletContext、ActionContext与ServletActionContext的区别
- ServletContext,ActionContext,ServletActionContext
- ServletContext,ActionContext,ServletActionContext
- 在线购物系统问题描述&领域词汇表
- Django中在template中使用静态文件
- linux虚拟机磁盘容量扩增
- Android nfc读卡模式流程
- Linux服务器的安装配置流程
- ActionContext,ServletContext和ServletActionContext有什么区别?
- OpenGL(九)使用 FrameBufferObject
- static和final的区别
- babel-polyfill的作用
- Volley和Ksoap框架整合
- Java 反射机制
- 使用TortoiseGit pull时,提示因为冲突导致拉取失败,怎么办?
- 彩票号码生成器
- Matlab studying~ 运算