当前位置: 首页>>代码示例>>Java>>正文


Java PageContext.setAttribute方法代码示例

本文整理汇总了Java中javax.servlet.jsp.PageContext.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java PageContext.setAttribute方法的具体用法?Java PageContext.setAttribute怎么用?Java PageContext.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.jsp.PageContext的用法示例。


在下文中一共展示了PageContext.setAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setValue

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
@Override
public void setValue(ELContext context, Object base, Object property,
        Object value) throws NullPointerException,
        PropertyNotFoundException, PropertyNotWritableException,
        ELException {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property != null) {
            String key = property.toString();
            PageContext page = (PageContext) context
                    .getContext(JspContext.class);
            int scope = page.getAttributesScope(key);
            if (scope != 0) {
                page.setAttribute(key, value, scope);
            } else {
                page.setAttribute(key, value);
            }
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:25,代码来源:ScopedAttributeELResolver.java

示例2: setAttribute

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
/**
 * Store bean in requested context.
 * If scope is <code>null</code>, save it in REQUEST_SCOPE context.
 *
 * @param pageContext Current pageContext.
 * @param name Name of the bean.
 * @param scope Scope under which bean is saved (page, request, session, application)
 *  or <code>null</code> to store in <code>request()</code> instead.
 * @param value Bean value to store.
 *
 * @exception JspException Scope name is not recognized as a valid scope
 */
public static void setAttribute(
    PageContext pageContext,
    String name,
    Object value,
    String scope)
    throws JspException {
        
    if (scope == null)
        pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE);
    else if (scope.equalsIgnoreCase("page"))
        pageContext.setAttribute(name, value, PageContext.PAGE_SCOPE);
    else if (scope.equalsIgnoreCase("request"))
        pageContext.setAttribute(name, value, PageContext.REQUEST_SCOPE);
    else if (scope.equalsIgnoreCase("session"))
        pageContext.setAttribute(name, value, PageContext.SESSION_SCOPE);
    else if (scope.equalsIgnoreCase("application"))
        pageContext.setAttribute(name, value, PageContext.APPLICATION_SCOPE);
    else {
        throw new JspException("Error - bad scope name '" + scope + "'");
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:TagUtils.java

示例3: setValue

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
@Override
public void setValue(ELContext context, Object base, Object property, Object value)
		throws NullPointerException, PropertyNotFoundException, PropertyNotWritableException, ELException {
	if (context == null) {
		throw new NullPointerException();
	}

	if (base == null) {
		context.setPropertyResolved(true);
		if (property != null) {
			String key = property.toString();
			PageContext page = (PageContext) context.getContext(JspContext.class);
			int scope = page.getAttributesScope(key);
			if (scope != 0) {
				page.setAttribute(key, value, scope);
			} else {
				page.setAttribute(key, value);
			}
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:ScopedAttributeELResolver.java

示例4: get

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
public static ScopeManager get(PageContext page) {
    ScopeManager mngr = (ScopeManager) page.getAttribute(MNGR_KEY);
    if (mngr == null) {
        mngr = new ScopeManager(page);
        page.setAttribute(MNGR_KEY, mngr);
    }
    return mngr;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:9,代码来源:ImplicitObjectELResolver.java

示例5: saveException

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
/**
 * Save the specified exception as a request attribute for later use.
 *
 * @param pageContext The PageContext for the current page
 * @param exception The exception to be saved
 */
public void saveException(PageContext pageContext, Throwable exception) {

    pageContext.setAttribute(
            Globals.EXCEPTION_KEY,
            exception,
            PageContext.REQUEST_SCOPE);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:TagUtils.java

示例6: getImplicitObjects

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
/**
 *
 * Finds the ImplicitObjects associated with the PageContext,
 * creating it if it doesn't yet exist.
 **/
public static ImplicitObjects getImplicitObjects (PageContext pContext)
{
  ImplicitObjects objs = 
    (ImplicitObjects)
    pContext.getAttribute (sAttributeName,
                           PageContext.PAGE_SCOPE);
  if (objs == null) {
    objs = new ImplicitObjects (pContext);
    pContext.setAttribute (sAttributeName,
                           objs,
                           PageContext.PAGE_SCOPE);
  }
  return objs;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:ImplicitObjectELResolver.java

示例7: restoreOriginalAttribute

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
static void restoreOriginalAttribute(PageContext pageContext, Map map, String attributeName) {
    // NOTE: This should probably use the original scope of the attribute when invoking the setAttribute() method.
    // That would involve storing the original scope in the map returned by getOriginalAttributes() method.
    // Will do that, if the need arises. Until then, will use the request-scope
    Object obj = map.get(attributeName);
    if (obj == null)
        pageContext.removeAttribute(attributeName);
    else
        pageContext.setAttribute(attributeName, obj, pageContext.REQUEST_SCOPE);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:11,代码来源:TagHelper.java

示例8: get

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
public static ScopeManager get(PageContext page) {
	ScopeManager mngr = (ScopeManager) page.getAttribute(MNGR_KEY);
	if (mngr == null) {
		mngr = new ScopeManager(page);
		page.setAttribute(MNGR_KEY, mngr);
	}
	return mngr;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:9,代码来源:ImplicitObjectELResolver.java

示例9: setValue

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
/**
 * If the base object is <code>null</code>, sets an existing scoped
 * attribute to the new value, or creates a new scoped attribute if one
 * does not exist by this name.
 *
 * <p>If the provided attribute name matches the key of an attribute 
 * in page scope, request scope, session scope, or application scope, the 
 * corresponding attribute value will be replaced by the provided value.
 * Otherwise, a new page scope attribute will be created with the
 * given name and value.</p>
 *
 * <p>The <code>propertyResolved</code> property of the 
 * <code>ELContext</code> object must be set to <code>true</code> by 
 * this resolver before returning if base is <code>null</code>. If 
 * this property is not <code>true</code> after this method is called,
 * the caller should ignore the return value.</p>
 *
 * @param context The context of this evaluation.
 * @param base Only <code>null</code> is handled by this resolver.
 *     Other values will result in an immediate return.
 * @param property The name of the scoped attribute to set.
 * @param val The value for the scoped attribute.
 * @throws NullPointerException if context is <code>null</code>.
 * @throws ELException if an exception was thrown while performing
 *     the property or variable resolution. The thrown exception
 *     must be included as the cause property of this exception, if
 *     available.
 */
public void  setValue(ELContext context,
                      Object base,
                      Object property,
                      Object val) {
    if (context == null) {
        throw new NullPointerException();
    }

    if (base == null) {
        context.setPropertyResolved(true);
        if (property instanceof String) {
            PageContext ctxt = (PageContext)
                                   context.getContext(JspContext.class);
            String attr = (String) property;
            if (ctxt.getAttribute(attr, PageContext.REQUEST_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.REQUEST_SCOPE);
            else if (ctxt.getAttribute(attr, PageContext.SESSION_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.SESSION_SCOPE);
            else if (ctxt.getAttribute(attr, PageContext.APPLICATION_SCOPE) != null)
                ctxt.setAttribute(attr, val, PageContext.APPLICATION_SCOPE);
            else {
                ctxt.setAttribute(attr, val, PageContext.PAGE_SCOPE);
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:ScopedAttributeELResolver.java

示例10: saveException

import javax.servlet.jsp.PageContext; //导入方法依赖的package包/类
/**
 * Save the specified exception as a request attribute for later use.
 *
 * @param pageContext The PageContext for the current page.
 * @param exception The exception to be saved.
 */
public static void saveException(PageContext pageContext, Throwable exception) {
    pageContext.setAttribute(Globals.EXCEPTION_KEY, exception, PageContext.REQUEST_SCOPE);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:TagUtils.java


注:本文中的javax.servlet.jsp.PageContext.setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。