私がやろうとしていることは比較的単純です
私の webapp には、次の 2 つのサーブレットがあります:
(いくつかの擬似コードを記述します)
サーブレット A コード: :
HttpSession sess = req.getSession();
String str = (String) sess.getAttribute("log");
if(str == null)
{
// send html page with a form
// to enter password and name
// data will be proceessed by servlet B
}
else
{
// send html page with a form
// to enter only a name
//data will be proceessed by servlet B
}
サーブレット B コード: :
HttpSession sess = req.getSession();
String logged = (String) sess.getAttribute("log");
if(logged == null)
{
//check if password correct
if(correct)
{
sess.setAttribute("log","ok");
// print name
// and tell the user
// that next time password
// will not be requested
}
else
{
// print error message
}
}
else
{
// print name
}
何らかの理由で、サーブレット A が 2 回目に呼び出された後、ユーザーがパスワードと名前を正しく入力した strはnullであるため、if部分が出力されます。
編集:
パスワードを挿入して servletB にリダイレクトされた後、ユーザーが自分で servletA の URL を書き込んだ場合、すべてがうまくいくことを発見しましたが、ユーザーが servletA: A HREF によって作成されたリンクを使用して前のページに戻ったときに機能しません。 =\"http://localhost:8080/Blog/ServletA\" 戻る
繰り返しますが、なぜこれが起こるのか何か提案はありますか?