页面执行后运行的Struts 2拦截器? [英] Struts 2 interceptor that runs after the page executes?

查看:90
本文介绍了页面执行后运行的Struts 2拦截器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts2.在每个页面执行开始时,我都使用拦截器创建数据库连接.

I'm using Struts 2. Using an interceptor, I create a database connection at the start of each page execution.

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

So for example, if a user goes to "myAction.do", it will create the database connection and then call myAction.do method.

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

What I'm looking for now is an interceptor or any other way to automatically call a method after the page execution, which will close the database connection.

有可能吗?

推荐答案

在拦截器中,您可以编写预处理和后处理逻辑.

In interceptor you can write pre processing and post processing logics.

预处理逻辑将在操作执行之前执行,并且 动作执行后执行后处理逻辑.

Pre processing logic will execute before the action executes and post processing logic executes after the action executes.

Struts2提供了非常强大的控制请求的机制 使用拦截器.拦截器负责大部分 请求处理.它们在之前和之后由控制器调用 调用动作后,它们就位于控制器和 行动.拦截器执行诸如记录,验证,文件之类的任务 上传,双重提交防护等.

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();之后将要执行的所有内容,将在执行操作后执行

Whatever you will write after invocation.invoke(); that will execute after executes action

请在此处查看示例

这篇关于页面执行后运行的Struts 2拦截器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆