開発メモ

開発用のメモです。

Session 新規/未作成時を制限する Interceptor

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class SessionTimeInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        HttpSession session = ServletActionContext.getRequest().getSession();
        if (session != null && !session.isNew()) {
            return invocation.invoke();
        }
        return ActionSupport.INPUT;
    }

}
Twitter: @asahina_alice