[英]session servlets and href tag
我想做的是相對簡單的
在我的webapp中,有以下兩個servlet:
(我會寫一些偽代碼)
servlet 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
}
servlet 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
}
由於某種原因,第二次調用Servlet A的原因是用戶輸入了密碼,並且正確輸入了名稱str為null,因此if部分被打印出來。
編輯:
我發現,如果用戶在插入密碼並重定向到servletB之后自己寫servletA的url一切正常,但是當用戶使用servletA創建的鏈接返回上一頁時,它不起作用。 = \\“ http:// localhost:8080 / Blog / ServletA \\”返回
再次,有什么建議為什么會這樣?
我相信它沒有進入您的if(correct)
塊,即correct
條件沒有得到滿足。 在此更正條件,並確保它在session
設置了log
屬性。 在會話中設置屬性后,該屬性將一直存在,直到會話過期或您將其刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.