我正在使用 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();
之后写什么都会在执行操作后执行
关于java - 在页面执行后运行的 Struts 2 拦截器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16475415/