當前位置: 首頁>>代碼示例>>Java>>正文


Java WebRequest.setAttribute方法代碼示例

本文整理匯總了Java中org.springframework.web.context.request.WebRequest.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java WebRequest.setAttribute方法的具體用法?Java WebRequest.setAttribute怎麽用?Java WebRequest.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.context.request.WebRequest的用法示例。


在下文中一共展示了WebRequest.setAttribute方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: afterCompletion

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count != null) {
		// Do not modify the PersistenceManager: just clear the marker.
		if (count > 1) {
			request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
		}
		else {
			request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		}
	}
	else {
		PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
				TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
		logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManagerFactoryUtils.releasePersistenceManager(
				pmHolder.getPersistenceManager(), getPersistenceManagerFactory());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:OpenPersistenceManagerInViewInterceptor.java

示例2: signupForm

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
@RequestMapping(value = "/signup", method = RequestMethod.GET)
public String signupForm(@ModelAttribute SocialUserDTO socialUserDTO, WebRequest request, Model model) {
    if (request.getUserPrincipal() != null)
        return "redirect:/";
    else {
        Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
        request.setAttribute("connectionSubheader",
                webUI.parameterizedMessage(MESSAGE_KEY_SOCIAL_SIGNUP,
                        StringUtils.capitalize(connection.getKey().getProviderId())),
                RequestAttributes.SCOPE_REQUEST);

        socialUserDTO = createSocialUserDTO(request, connection);

        ConnectionData connectionData = connection.createData();
        SignInUtils.setUserConnection(request, connectionData);

        model.addAttribute(MODEL_ATTRIBUTE_SOCIALUSER, socialUserDTO);
        return SIGNUP_VIEW;
    }
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:21,代碼來源:UserController.java

示例3: preHandle

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	if (TransactionSynchronizationManager.hasResource(getPersistenceManagerFactory())) {
		// Do not modify the PersistenceManager: just mark the request accordingly.
		String participateAttributeName = getParticipateAttributeName();
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManager pm =
				PersistenceManagerFactoryUtils.getPersistenceManager(getPersistenceManagerFactory(), true);
		TransactionSynchronizationManager.bindResource(
				getPersistenceManagerFactory(), new PersistenceManagerHolder(pm));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:OpenPersistenceManagerInViewInterceptor.java

示例4: getAsyncManager

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
/**
 * Obtain the {@link WebAsyncManager} for the current request, or if not
 * found, create and associate it with the request.
 */
public static WebAsyncManager getAsyncManager(WebRequest webRequest) {
	int scope = RequestAttributes.SCOPE_REQUEST;
	WebAsyncManager asyncManager = (WebAsyncManager) webRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, scope);
	if (asyncManager == null) {
		asyncManager = new WebAsyncManager();
		webRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager, scope);
	}
	return asyncManager;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:WebAsyncUtils.java

示例5: storeAttribute

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
@Override
public void storeAttribute(WebRequest request, String attributeName, Object attributeValue) {
	Assert.notNull(request, "WebRequest must not be null");
	Assert.notNull(attributeName, "Attribute name must not be null");
	Assert.notNull(attributeValue, "Attribute value must not be null");
	String storeAttributeName = getAttributeNameInSession(request, attributeName);
	request.setAttribute(storeAttributeName, attributeValue, WebRequest.SCOPE_SESSION);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:DefaultSessionAttributeStore.java

示例6: preHandle

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
@Override
public void preHandle(WebRequest request) throws DataAccessException {

	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applyCallableInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
		// do not modify the EntityManager: just mark the request accordingly
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
		try {
			EntityManager em = createEntityManager();
			EntityManagerHolder emHolder = new EntityManagerHolder(em);
			TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

			AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
		}
		catch (PersistenceException ex) {
			throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:OpenEntityManagerInViewInterceptor.java

示例7: decrementParticipateCount

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
private boolean decrementParticipateCount(WebRequest request) {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count == null) {
		return false;
	}
	// Do not modify the Session: just clear the marker.
	if (count > 1) {
		request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
	}
	else {
		request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	}
	return true;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:OpenEntityManagerInViewInterceptor.java

示例8: preHandle

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
/**
 * Open a new Hibernate {@code Session} according and bind it to the thread via the
 * {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor");
		Session session = openSession();
		SessionHolder sessionHolder = new SessionHolder(session);
		TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

		AsyncRequestInterceptor asyncRequestInterceptor =
				new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
		asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
		asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:OpenSessionInViewInterceptor.java

示例9: preHandle

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:OpenSessionInViewInterceptor.java

示例10: preHandle

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
@Override
public void preHandle(WebRequest request) {
    final List<FlashMessage> messages = flash.getMessages();
    request.setAttribute("flash", messages, RequestAttributes.SCOPE_REQUEST);
    for (FlashMessage message : messages) {
        final String key = "flash" + message.getResolvable().getCodes()[0];
        request.setAttribute(key, message, RequestAttributes.SCOPE_REQUEST);
    }
    flash.reset();
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:11,代碼來源:FlashInterceptor.java

示例11: setUserConnection

import org.springframework.web.context.request.WebRequest; //導入方法依賴的package包/類
public static void setUserConnection(WebRequest request, ConnectionData connectionData) {
	String attribute = GlobalController.SESSION_USER_CONNECTION;
	request.setAttribute(attribute, connectionData, RequestAttributes.SCOPE_SESSION);
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:5,代碼來源:SignInUtils.java


注:本文中的org.springframework.web.context.request.WebRequest.setAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。