- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
要在 Struts 2 中获取 servlet 请求,我们可以使用 ServletRequestAware
或 ServletActionContext
。但是,在特定的互联网中 resource ,它被告知应该使用 ServletRequestAware
而不是 ServletActionContext
。
这是否与 ServletActionContext
将成为多线程环境中的共享资源这一事实有关,或者这背后是否有任何其他原因?
最佳答案
ServletRequestAware
是一种更好的方法,因为它将操作方法与静态访问器分离。
为了使用ServletActionContext
测试某些东西,您需要模拟静态方法和 模拟请求。要测试 ServletRequestAware
方法,您只需模拟请求即可。
虽然存在使模拟静态方法更容易的工具,但实现接口(interface)和传递模拟请求更容易。这就是 ServletRequestAware
存在的原因。
关于java - 为什么使用 ServletRequestAware 而不是 ServletActionContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26699019/
我将从 ServletActionContext 中删除一些属性,但稍后当我迭代 ServletActionContext 时,属性会继续显示。 ServletActionContext.getReq
我正在使用 servlet 过滤器,尝试获取与当前请求关联的操作。 我的过滤器的相关部分: private ServletContext context; public void init(Filte
要在 Struts 2 中获取 servlet 请求,我们可以使用 ServletRequestAware 或 ServletActionContext。但是,在特定的互联网中 resource ,它
请告诉我 ServletActionContext 和 ServletContext 有什么区别?ServletContext 在所有 servlet 和 Action 之间共享,而 ServletA
我有一个 struts 应用程序,可以在其中获取我正在使用此代码的 servlet 上下文 ServletContext servletContext = ServletActionContext.g
我有以下代码。 HttpServletResponse response = mock(HttpServletResponse.class); System.out.println("
我必须在 Struts2 中的选定操作上使用加载栏,并且正在使用 ServletActionContext,但收到 NullPointerException。 ActionContext.getCon
我是一名优秀的程序员,十分优秀!