java - 在页面执行后运行的 Struts 2 拦截器?

标签 java struts2 interceptor

我正在使用 Struts 2。使用拦截器,我在每个页面执行开始时创建一个数据库连接。

例如,如果用户转到“myAction.do”,它将创建数据库连接,然后调用 myAction.do 方法。

我现在正在寻找的是一个拦截器或任何其他方式来在页面执行后自动调用一个方法,这将关闭数据库连接。

这可能吗?

最佳答案

在拦截器中你可以编写预处理和后处理逻辑。

预处理逻辑将在 Action 执行之前执行,并且 后处理逻辑在 Action 执行后执行。

Struts2 provides very powerful mechanism of controlling a request using Interceptors. Interceptors are responsible for most of the request processing. They are invoked by the controller before and after invoking action, thus they sits between the controller and action. Interceptors performs tasks such as Logging, Validation, File Upload, Double-submit guard etc.

无论你在 invocation.invoke(); 之后写什么都会在执行操作后执行

SEE HERE FOR EXAMPLE

关于java - 在页面执行后运行的 Struts 2 拦截器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16475415/

相关文章:

java - GraphStream 中更具可读性的图形 - JAVA

java.lang.IllegalArgumentException : hostname cannot be null when trying to obtain AWS ECR Authentication Token 异常

java - Spring Boot : Interceptor to read particular field from request and set it in the response

struts2 - WebSphere Application Server 8 (WAS 8) 上的 Struts 2 和自定义错误页面

java - Struts2 触发表在完成时加载

methods - 如何在 Guice 中定义方法拦截器的顺序?

java - 如何为SlingClient编写拦截器

java - 在端口 8080 上执行时 JSP/Servlets 程序出错 :

java - 卡在二维数组中

java - HTTP 404 错误 - 在简单的 Struts2 应用程序中