我遇到了struts 2應用程序的問題。 用戶1成功登錄並重定向到某個頁面。 之後, 用戶2嘗試從她的機器登錄,她被重定向到user1的登錄頁面。Struts 2:用戶1登錄並獲取之前從另一個macine登錄的用戶的數據
我不確定這是Web容器(Web邏輯)的問題還是我編碼中的一些問題。我無法弄清楚我可能出錯的地方以及服務器如何從另一個用戶提供數據會話。
登錄操作實現sessionaware,我有會話映射的setter和getter。 如果登錄操作返回成功,則用戶被重定向到另一個操作,此操作再次執行sessionaware。
這個問題真的很奇怪。任何人都可以提出任何可能發生的原因。
此外,爲了增加複雜性,相同的應用程序耳朵在本地工作正常。只有當我試圖將它部署到測試服務器時纔會出現此問題。
這是intercepotr代碼。我不認爲這是線程不安全的。
public class UserAuthentication extends AbstractInterceptor
{
public UserAuthentication()
{
}
public void init(){//System.out.println("init'd");
}
public void destroy() {System.out.println("destroyed");}
public String intercept(ActionInvocation invocation) throws Exception
{
String className = invocation.getAction().toString();
Map OHRMS = ActionContext.getContext().getSession();
System.out.println("EmpInfoUpd: " + new Date() + " Inside the interceptor: ");
System.out.println("EmpInfoUpd: " + new Date() + " Interceptor called for action: " + className);
System.out.println("EmpInfoUpd: " + new Date() + " Now printing the entries of session map from interceptor: " + OHRMS);
Employee temp = (Employee)OHRMS.get("emp");
if(temp==null)
{ System.out.println("EmpInfoUpd: " + new Date() + " The session had no \"emp\" object. Interceptor returned \"login\" ");
return "login";
}
System.out.println("EmpInfoUpd: " + new Date() + " The session had \"emp\" object with Employee name: " + temp.getFullName()+ " Interceptor returned \"login\" ");
return invocation.invoke();
}
}
在這一點上,這是不可能說的。當你說它不是在本地發生的時候,你的意思是*永遠*,包括負載下,或者「從來沒有當我在一臺機器上用兩個人嘗試它」? –
永不......只有當它在負載下時,測試服務器上纔會出現問題......即使兩個用戶登錄,測試服務器上也會出現問題。第二個登錄用戶將看到第一個用戶的數據。 – Rpant
默認攔截器堆棧? –