本文整理了Java中org.sakaiproject.tool.api.Session.setAttribute()
方法的一些代码示例,展示了Session.setAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Session.setAttribute()
方法的具体详情如下:
包路径:org.sakaiproject.tool.api.Session
类名称:Session
方法名:setAttribute
[英]Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced.
After this method executes, and if the new object implements SessionBindingListener
, Sakai calls SessionBindingListener.valueBound
.
If an object was already bound to this session of this name that implements SessionBindingListener
, its SessionBindingListener.valueUnbound
method is called.
If the value passed in is null, this has the same effect as calling removeAttribute()[[$4$]]
[中]使用指定的名称将对象绑定到此会话。如果同名对象已绑定到会话,则会替换该对象。
执行此方法后,如果新对象实现SessionBindingListener
,Sakai将调用SessionBindingListener.valueBound
。
如果某个对象已绑定到此实现SessionBindingListener
的同名会话,则会调用其SessionBindingListener.valueUnbound
方法。
如果传入的值为null,则与调用removeAttribute()[[$4$]]
具有相同的效果
代码示例来源:origin: stackoverflow.com
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
session.setAttribute( "someKey", someValue);
代码示例来源:origin: stackoverflow.com
Session session = Sessions.getCurrent();
session.setAttribute("my_stored_data", myStoredData);
代码示例来源:origin: stackoverflow.com
Session session = request.getSession(true);
session.setAttribute("clientId", "abc");
代码示例来源:origin: stackoverflow.com
public class MyVm{
....
private Item item;
@Init
public void initMyVM(){
Item item = Sessions.getCurrent().getAttribute("myItem");
if(item == null)
//do normal intialization
}
public Item getItem() {
return item;
}
public void setItem(Item item) { // or wherever it changes
this.item = item;
Session session = Sessions.getCurrent();
session.setAttribute("myItem", item); // or wherever it changes
}
@Command("onTimer")
pulic void comandRefresh(){
Executions.sendRedirect("");
}
....
}
代码示例来源:origin: stackoverflow.com
public class LonginServelt extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response){
User user = userService.checkUserCredential(username,password);
Session session = request.getSession();
session.setAttribute("user",user);
}
}
<c:choose>
<c:when test="${isAdmin}">
You got Gold
</c:when>
<c:when test="${isCustomer}">
You got Silver
</c:when>
<c:when test="${isProducer}">
You got Bronze
</c:when>
<c:otherwise>
Better luck next time
</c:otherwise>
</c:choose>
代码示例来源:origin: sakaiproject/sakai
public void setLocale(Locale toset) {
sessionManager.getCurrentSession().setAttribute("locale", toset);
}
代码示例来源:origin: stackoverflow.com
//Storing value
Session session = request.getSession();
session.setAttribute("key", "value");
//Retrieve value
session.getAttribute("key")
代码示例来源:origin: stackoverflow.com
public void logOut(HttpServletRequest req) {
final Session s = req.getSession();
final String userId = s.getParameter("userId");
// Log the user out.
// Mark the session was closed on-command.
s.setAttribute("logOut", Boolean.TRUE);
}
代码示例来源:origin: uk.org.ponder.sakairsf/sakairsf
public void setLocale(Locale toset) {
sessionManager.getCurrentSession().setAttribute("locale", toset);
}
代码示例来源:origin: stackoverflow.com
public void logIn(HttpServletRequest req) {
final String uniqueId = s.getParameter("uniqueId");
Session s = req.getSession(false);
// User returning after time-out?
if (s == null && uniqueId != null) {
// Create new session...
s = req.getSession(true);
// ...assign it the same uniqueId...
s.setAttribute("uniqueId", uniqueId);
// ...and put back old session data.
copyDataToSession(s, getOldSessionData(uniqueId));
}
else {
// User logging in as usual.
}
}
代码示例来源:origin: stackoverflow.com
public Page1(Pageparameters parameters) {
super(parameters);
String value = parameters.get("magicProperty").toString();
if (value != null && isValid(value)) {
Serializable key = createKey(value);
Session session = getSession();
session.setAttribute("key", key);
session.bind();
throw new RestartResponseException(Page2.class);
}
}
代码示例来源:origin: stackoverflow.com
String name = "myCoolVariable";
MyObject originalValue = getMyCoolVariable();
Session session = Sessions.getCurrent();
session.setAttribute(name, originalValue);
...
if (session.hasAttribute(name)) {
MyObject retrievedValue = (MyObject) session.getAttribute(name);
}
代码示例来源:origin: sakaiproject/sakai
private void refreshAutoFavorites(Session session) {
Long lastRefreshTime = (Long)session.getAttribute(AUTO_FAVORITES_LAST_REFRESHED_TIME);
if (lastRefreshTime == null) {
lastRefreshTime = Long.valueOf(0);
}
long now = System.currentTimeMillis();
if ((now - lastRefreshTime) > AUTO_FAVORITES_REFRESH_INTERVAL_MS) {
// Fetch the list of favorites, which will in turn populate the auto favorites.
try {
new FavoritesHandler().userFavorites(session.getUserId());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
session.setAttribute(AUTO_FAVORITES_LAST_REFRESHED_TIME, now);
}
}
代码示例来源:origin: org.sakaiproject.portal/sakai-portal-impl
private void refreshAutoFavorites(Session session) {
Long lastRefreshTime = (Long)session.getAttribute(AUTO_FAVORITES_LAST_REFRESHED_TIME);
if (lastRefreshTime == null) {
lastRefreshTime = Long.valueOf(0);
}
long now = System.currentTimeMillis();
if ((now - lastRefreshTime) > AUTO_FAVORITES_REFRESH_INTERVAL_MS) {
// Fetch the list of favorites, which will in turn populate the auto favorites.
try {
new FavoritesHandler().userFavorites(session.getUserId());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
session.setAttribute(AUTO_FAVORITES_LAST_REFRESHED_TIME, now);
}
}
代码示例来源:origin: sakaiproject/sakai
public void putTokenState(String tokenID, Object trs) {
ToolSession toolSession = sessionmanager.getCurrentToolSession();
if (toolSession == null) {
sessionmanager.getCurrentSession().setAttribute(tokenID, trs);
} else {
toolSession.setAttribute(tokenID, trs);
}
}
代码示例来源:origin: uk.org.ponder.sakairsf/sakairsf
public void putTokenState(String tokenID, Object trs) {
ToolSession toolSession = sessionmanager.getCurrentToolSession();
if (toolSession == null) {
sessionmanager.getCurrentSession().setAttribute(tokenID, trs);
}
else {
toolSession.setAttribute(tokenID, trs);
}
}
代码示例来源:origin: org.sakaiproject.portal/sakai-portal-impl
if (req.getQueryString() != null )
returnUrl += "?"+req.getQueryString();
session.setAttribute(Tool.HELPER_DONE_URL, returnUrl);
代码示例来源:origin: org.sakaiproject.kernel/sakai-kernel-impl
/**
* {@inheritDoc}
*/
public boolean setUserEffectiveRole(String azGroupId, String role) {
if (!unlock(SiteService.SITE_ROLE_SWAP, azGroupId))
return false;
// set the session attribute with the roleid
sessionManager().getCurrentSession().setAttribute(ROLESWAP_PREFIX + azGroupId, role);
resetSecurityCache(azGroupId);
return true;
}
代码示例来源:origin: sakaiproject/sakai
session.setAttribute(Tool.HELPER_DONE_URL, loggedOutUrl);
代码示例来源:origin: sakaiproject/sakai
public String setCurrentUser(String userReference) {
if (userReference == null) {
throw new IllegalArgumentException("userReference cannot be null");
}
String userId = getUserIdFromRef(userReference);
try {
// make sure the user id is valid
userDirectoryService.getUser(userId);
} catch (UserNotDefinedException e) {
throw new IllegalArgumentException("Invalid user reference ("+userReference+"), could not find user");
}
Session currentSession = sessionManager.getCurrentSession();
if (currentSession == null) {
// start a session if none is around
currentSession = sessionManager.startSession(userId);
}
String currentUserId = currentSession.getUserId();
if (currentSession.getAttribute(CURRENT_USER_MARKER) == null) {
// only set this if it is not already set
if (currentUserId == null) {
currentUserId = "";
}
currentSession.setAttribute(CURRENT_USER_MARKER, currentUserId);
}
currentSession.setUserId(userId);
currentSession.setActive();
sessionManager.setCurrentSession(currentSession);
authzGroupService.refreshUser(userId);
return getUserRefFromUserId(currentUserId);
}
内容来源于网络,如有侵权,请联系作者删除!