私は Struts 2 を使用しています。ユーザーがナビゲートして別のアクションを実行するタイミングを識別して傍受することは可能ですか?
ユーザーが現在行っているアクションとは異なるアクションに移動するかどうかを特定する必要があります。
それは簡単です。Struts 2 インターセプターを使用するだけです。
public class TestInterceptor extends AbstractInterceptor {
public String intercept(ActionInvocation invocation) throws Exception {
// Do checking here, get user from session or from parameter is OK.
// Example:
// string returned below will be redirected to result of Struts 2 action
String roleName = user.getRole().getName();
if ("admin".equals(roleName) {
return "admin";
} else if("user".equals(roleName)) {
return "user";
}
// This means if roleName is not admin or user, the action will be invoked
return invocation.invoke();
}
}
次に、struts.xml構成に上記のインターセプターを追加するだけです。これはあなたが望むものだと思いますよね?私はいつもこのインターセプターを使用しています。
サンプルについては、 http: //struts.apache.org/2.x/docs/interceptors.htmlまたはhttp://www.benmccann.com/blog/struts-2-tutorial-interceptors/を参照してください。