0
在我的Java EE應用程序,我宣佈了下述寧靜類SessionContext.getCallerPrincipal.getName()返回「匿名」
@Path("userProfile")
@Stateless
public class UserProfileRestful {
@Resource
private SessionContext sessionContext;
@Path("userName")
@GET
@Produces(MediaType.Text_Palin)
public String findCurrentUserName(){
return sessionContext.getCallerPrincipal.getName();
}
}
旨在通過任何客戶端獲取的當前登錄用戶的用戶名。
我登錄後使用用戶名「myuser的」,我剛纔粘貼以下網址到Web瀏覽器在新標籤
http://localhost:8080/MyApp/rest/userProfile/userName
和顯示的反應是如期望的那樣「爲myuser」。
現在我試圖從另一個ExtJS的應用程序(不要求身份驗證)執行一個Ajax請求中獲取用戶名如下:
Ext.Ajax.Request({
url : "http://localhost:8080/MyApp/rest/userProfile/userName",
success : function(response,options){
alert('username : ' + response.responseText);
},
failure : function(){
alert('request failed');
}
});
的提醒結果是「無名氏」,儘管我仍然在同一會話期間以「myuser」身份登錄。
那麼,爲什麼調用者主體在第二種情況下發生變化,並且是否有解決方案?