0

ログインフォームがあるWebサイトがあります。ログインが成功した場合、オブジェクトユーザーをセッションに入れ、次のように別のページ(セッション属性が必要)に移動します。

-Javaサーブレット-

 request.getSession(true).setAttribute("utente", u);
 request.getSession(true).setAttribute("abbonamento", a);
 request.getRequestDispatcher("HomeUtente.jsp").forward(request, response);

-Jspページ-

    <%
    Utente u = null;
    Abbonamento a = null;
    try {
        u = (Utente) session.getAttribute("utente");
        a = (Abbonamento) session.getAttribute("abbonamento");
    } catch (Exception e) {
        a = null;
        u = null;
        e.printStackTrace();
    }
%>

さて、一度これを行うと問題ありませんが、ページを更新するとセッションが削除されるようです。

これは、ページを(デバッグモードで)更新すると、aとuの両方がnullになるためだと思います。

何か案が?

4

1 に答える 1

-1

Java Session -

HttpSession getSession(boolean create) -

Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.

So in your program as you are using -

request.getSession(true) -

it is always returning a new session and previous session variables are deleted.

also you can view the following link for better understanding -

How to check if session exists or not?

于 2013-03-10T19:45:28.533 に答える