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


Java RequestAttributes.setAttribute方法代碼示例

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


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

示例1: adjustViewName

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
public static String adjustViewName(String viewName) {
		
		RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();

		String jspPrefix = (String) requestAttributes.getAttribute("jspPrefix", RequestAttributes.SCOPE_REQUEST);
		if (jspPrefix == null || "".equals(jspPrefix)) jspPrefix = comDefaultPath;
		
		String jspPage = jspPrefix + viewName;	
		
//		LOG.debug("jspPage = " + jspPage);

		// if tiles exist, forward tiles layout
		String aTrgetId   = (String) requestAttributes.getAttribute("curTrgetId", RequestAttributes.SCOPE_REQUEST);
		String aCurMenuNo = (String) requestAttributes.getAttribute("curMenuNo", RequestAttributes.SCOPE_REQUEST);
		if( aTrgetId != null
				&& aTrgetId.startsWith("CMMNTY_") 
				&& aCurMenuNo != null
				&& !"".equals(aCurMenuNo) )  {
			
			requestAttributes.setAttribute("jspPage", jspPage, RequestAttributes.SCOPE_REQUEST);
			
			return "forward:/cop/cmy/CmmntyTilesPage.do";
		}
		
		return jspPage;
	}
 
開發者ID:aramsoft,項目名稱:aramcomp,代碼行數:27,代碼來源:WebUtil.java

示例2: getErrorAttributes

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
@Override
public Map<String, Object> getErrorAttributes(
        RequestAttributes requestAttributes,
        boolean includeStackTrace) {

    Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, true);

    Throwable throwable = getError(requestAttributes);

    ErrorStatusCodeAndMessage errorStatusCodeAndMessage = exceptionStatusCodeAndMessageResolver
        .resolveStatusCodeAndMessage(
            throwable,
            (String) errorAttributes.get("message"),
            (Integer) requestAttributes.getAttribute("javax.servlet.error.status_code", 0));

    errorAttributes.put("error", errorStatusCodeAndMessage.getMessage());
    requestAttributes.setAttribute("javax.servlet.error.status_code", errorStatusCodeAndMessage.getStatusCode(), 0);
    errorAttributes.put("status", errorStatusCodeAndMessage.getStatusCode());


    log.error(
        errorStatusCodeAndMessage.getMessage(),
        StructuredArguments.keyValue("errorCode", errorStatusCodeAndMessage.getMessage()),
        StructuredArguments.keyValue("stackTrace", errorAttributes.get("trace"))
    );


    if (!globalIncludeStackTrace) {
        errorAttributes.remove("exception");
        errorAttributes.remove("trace");
    }
    errorAttributes.remove("message");

    return errorAttributes;
}
 
開發者ID:hmcts,項目名稱:document-management-store-app,代碼行數:36,代碼來源:ApiErrorAttributes.java

示例3: setWxRequestToRequest

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
/**
 * 同上麵方法,不過request從RequestContextHolder中取
 * @param wxRequest
 */
public static void setWxRequestToRequest(WxRequest wxRequest) {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        requestAttributes.setAttribute(WX_REQUEST_ATTRIBUTE, wxRequest, RequestAttributes.SCOPE_REQUEST);
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:11,代碼來源:WxWebUtils.java

示例4: isValid

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
/**
 * 數據驗證
 * 
 * @param target
 *            驗證對象
 * @param groups
 *            驗證組
 * @return 驗證結果
 */
protected boolean isValid(Object target, Class<?>... groups) {
	Set<ConstraintViolation<Object>> constraintViolations = validator.validate(target, groups);
	if (constraintViolations.isEmpty()) {
		return true;
	} else {
		RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
		requestAttributes.setAttribute(CONSTRAINT_VIOLATIONS_ATTRIBUTE_NAME, constraintViolations, RequestAttributes.SCOPE_REQUEST);
		return false;
	}
}
 
開發者ID:justinbaby,項目名稱:my-paper,代碼行數:20,代碼來源:BaseController.java

示例5: addLog

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
/**
 * 添加日誌
 * 
 * @param content
 *            內容
 */
protected void addLog(String content) {
	if (content != null) {
		RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
		requestAttributes.setAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME, content, RequestAttributes.SCOPE_REQUEST);
	}
}
 
開發者ID:justinbaby,項目名稱:my-paper,代碼行數:13,代碼來源:BaseController.java

示例6: cmmntyMainPageHandler

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
private String cmmntyMainPageHandler(
		String cmmntyId, 
		String menuId, 
		String contentUrl) {

	if( cmmntyId == null || cmmntyId.equals("") ) {
		throw new RuntimeException("cmmntyId not found");
	}
	
       CommunityVO communityVO = cmmntyService.getCommunityInfo(cmmntyId, menuId);

       // --------------------------------
	// 컨텐트 URL 정보
	// --------------------------------
	if( "".equals(menuId) && communityVO.getTopMenuList().size() != 0 ) {
		menuId = communityVO.getTopMenuList().get(0).get("menuNo").toString();
	}
	
	if( "".equals(contentUrl) ) {
		contentUrl = getMenuInfo(communityVO, menuId, "chkURL");
		if( "".equals(contentUrl) ) {
			contentUrl =  "/cop/cmy/CmmntyMainContents.do";
		}
	}
	
	RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
	requestAttributes.setAttribute("curTrgetId", communityVO.getCmmntyId(), RequestAttributes.SCOPE_REQUEST);
	requestAttributes.setAttribute("curMenuNo", menuId, RequestAttributes.SCOPE_REQUEST);

   	return "forward:"+contentUrl;
}
 
開發者ID:aramsoft,項目名稱:aramcomp,代碼行數:32,代碼來源:CmyMenuHomeController.java

示例7: setAttribute

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
@Override
public void setAttribute(RequestAttributes request, String name, Object value) {
    request.setAttribute(name, value, RequestAttributes.SCOPE_SESSION);
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:5,代碼來源:HttpSessionSessionStrategy.java

示例8: tagWithException

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
public static void tagWithException(Throwable exception) {
    RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
    attributes.setAttribute(EXCEPTION_ATTRIBUTE, exception,
        RequestAttributes.SCOPE_REQUEST);
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:6,代碼來源:MetricsFilter.java

示例9: setWxWebUserToSession

import org.springframework.web.context.request.RequestAttributes; //導入方法依賴的package包/類
public static void setWxWebUserToSession(WxWebUser wxWebUser) {
    RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
    if (requestAttributes != null) {
        requestAttributes.setAttribute(WX_SESSION_USER, wxWebUser, RequestAttributes.SCOPE_SESSION);
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:7,代碼來源:WxWebUtils.java


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