0

新しいセッションを作成し、同時に以前のセッションを維持するという問題に直面しています。

私のコードはサーブレットにあります。IE 以外のすべてのブラウザー、および IE7 以前のバージョンでも機能しますが、IE8 と IE9 では機能しません。私は、IE8 と IE9 が新しいリクエストごとに同じセッションを使用することをよく知っていました。しかし、Java EE アプリケーションの新しい初期リクエストごとに新しいセッションを作成したいと考えています。HTTPSessionセッションが null のときに初めてnew を作成するコードを書き、新しいセッションのコードも追加しました。

すべてのページで非表示の変数値を維持したり、URL を介してセッション ID を送信したりせずに、新しいセッションの変更をコード化するにはどうすればよいですか? 2 つ以上のセッションを分離する他の方法はありますか?

私のサーブレットコードのスナップショットは以下のようなものです:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    process(request, response);
}

private void process (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String strErrorMsg = null;
    response.setContentType ( "text/html" );
    HttpSession session = null;
    Cookie cookies[] = request.getCookies();

    if (session == null) {
        ServletContext appContext = getServletContext();
        WebProcessContextBuilder builder =  WebProcessContextBuilder.getInstance();
        ProcessContext objContext = null;
        try {
            session = request.getSession(true);
            // Code for setting some initial session attributes and forwarding request 
            // to first window to display.
        }
    }

    if (session != null && session.isNew()) {
        // Code for new session to forward my request with saving session id 
        // as well as setting session attributes
    } else {
        // code for showing alert message like "Session active in another window or tab.";
    }
}

上記のコードを使用して、2 回目に新しいアプリケーションをロードしようとすると、常にエラー メッセージが表示されます。これは、null に等しくなくsession.isNew、IE8 と IE9 の場合は常に false であるセッションを取得しているためです。それ以外の場所では正常に動作します。

4

1 に答える 1