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


Java ServletContext.getAttribute方法代码示例

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


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

示例1: contextInitialized

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent event) {
  super.contextInitialized(event);

  final ServletContext context = event.getServletContext();
  final Registry registry = (Registry) context.getAttribute(Registry.class.getName());
  final ResteasyProviderFactory providerFactory =
      (ResteasyProviderFactory) context.getAttribute(ResteasyProviderFactory.class.getName());
  final ModuleProcessor processor = new ModuleProcessor(registry, providerFactory);

  final List<? extends Module> appModules = getModules(context);

  List<Module> modules = Lists.newArrayList();
  modules.addAll(appModules);

  injector = GuiceLifecycleContainers.initialize(this, modules);

  withInjector(injector);

  processor.processInjector(injector);
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:22,代码来源:ResteasyContextListener.java

示例2: isInstrumentationAccessAllowed

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Checks the user has privileges to access to instrumentation servlets.
 * <p/>
 * If <code>hadoop.security.instrumentation.requires.admin</code> is set to FALSE
 * (default value) it always returns TRUE.
 * <p/>
 * If <code>hadoop.security.instrumentation.requires.admin</code> is set to TRUE
 * it will check that if the current user is in the admin ACLS. If the user is
 * in the admin ACLs it returns TRUE, otherwise it returns FALSE.
 *
 * @param servletContext the servlet context.
 * @param request the servlet request.
 * @param response the servlet response.
 * @return TRUE/FALSE based on the logic decribed above.
 */
public static boolean isInstrumentationAccessAllowed(
  ServletContext servletContext, HttpServletRequest request,
  HttpServletResponse response) throws IOException {
  Configuration conf =
    (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE);

  boolean access = true;
  boolean adminAccess = conf.getBoolean(
    CommonConfigurationKeys.HADOOP_SECURITY_INSTRUMENTATION_REQUIRES_ADMIN,
    false);
  if (adminAccess) {
    access = hasAdministratorAccess(servletContext, request, response);
  }
  return access;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:31,代码来源:HttpServer.java

示例3: contextDestroyed

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void contextDestroyed(ServletContextEvent sce) {
    ServletContext sc = sce.getServletContext();
    Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    if (obj instanceof WsServerContainer) {
        ((WsServerContainer) obj).destroy();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:9,代码来源:WsContextListener.java

示例4: getXFormFilesAndIndex

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private void getXFormFilesAndIndex(ServletContext context){
	if(index == null)
		index = (SimpleLuceneIndex)context.getAttribute("index");
	if(adn_to_oai_file == null)
		adn_to_oai_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("adn-to-oai-dc-xsl"));
	if(namespace_out_file == null)
		namespace_out_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("namespace-out-xsl"));				
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:11,代码来源:ADNToOAIDCFormatConverter.java

示例5: getInstance

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public static JspApplicationContextImpl getInstance(ServletContext context) {
    if (context == null) {
        throw new IllegalArgumentException("ServletContext was null");
    }
    JspApplicationContextImpl impl = (JspApplicationContextImpl) context
            .getAttribute(KEY);
    if (impl == null) {
        impl = new JspApplicationContextImpl();
        context.setAttribute(KEY, impl);
    }
    return impl;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:13,代码来源:JspApplicationContextImpl.java

示例6: getObject

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * 从web的作用域中获取对象...
 * @param key
 * @param clazz
 * @param <T>
 * @return
 */
public static <T>T getObject(String key, Object obj, Class<T> clazz) {
    AssertUtils.notNull(key,obj,clazz);
    if (obj instanceof HttpServletRequest) {
        HttpServletRequest request = (HttpServletRequest) obj;
        return (T) request.getAttribute(key);
    }else if(obj instanceof HttpSession){
        HttpSession session = (HttpSession) obj;
        return (T) session.getAttribute(key);
    }else if(obj instanceof ServletContext){
        ServletContext servletContext = (ServletContext) obj;
        return (T) servletContext.getAttribute(key);
    }
    throw new IllegalArgumentException("obj must be {HttpServletRequest|HttpSession|ServletContext} ");
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:22,代码来源:WebUtils.java

示例7: sessionDestroyed

import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
    String sessionId = httpSessionEvent.getSession().getId();
    System.out.println("当前销毁的sessionId = " + sessionId);
    ServletContext servletContext = httpSessionEvent.getSession().getServletContext();
    Object userCount = servletContext.getAttribute("userCount");
    if (userCount == null) {
        servletContext.setAttribute("userCount", 0);
    } else {
        servletContext.setAttribute("userCount", Integer.parseInt(userCount.toString()) - 1);
    }
}
 
开发者ID:aimkiray,项目名称:sgroup,代码行数:13,代码来源:NewSessionListener.java

示例8: getELInterpreter

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Obtain the correct EL Interpreter for the given web application.
 */
public static ELInterpreter getELInterpreter(ServletContext context)
        throws Exception {

    ELInterpreter result = null;

    // Search for an implementation
    // 1. ServletContext attribute (set by application or cached by a
    //    previous call to this method).
    Object attribute = context.getAttribute(EL_INTERPRETER_CLASS_NAME);
    if (attribute instanceof ELInterpreter) {
        return (ELInterpreter) attribute;
    } else if (attribute instanceof String) {
        result = createInstance(context, (String) attribute);
    }

    // 2. ServletContext init parameter
    if (result == null) {
        String className =
                context.getInitParameter(EL_INTERPRETER_CLASS_NAME);
        if (className != null) {
            result = createInstance(context, className);
        }
    }

    // 3. Default
    if (result == null) {
        result = DEFAULT_INSTANCE;
    }

    // Cache the result for next time
    context.setAttribute(EL_INTERPRETER_CLASS_NAME, result);
    return result;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:37,代码来源:ELInterpreterFactory.java

示例9: getInstance

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public static JspApplicationContextImpl getInstance(ServletContext context) {
	if (context == null) {
		throw new IllegalArgumentException("ServletContext was null");
	}
	JspApplicationContextImpl impl = (JspApplicationContextImpl) context.getAttribute(KEY);
	if (impl == null) {
		impl = new JspApplicationContextImpl();
		context.setAttribute(KEY, impl);
	}
	return impl;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:12,代码来源:JspApplicationContextImpl.java

示例10: getXFormFilesAndIndex

import javax.servlet.ServletContext; //导入方法依赖的package包/类
private void getXFormFilesAndIndex(ServletContext context) {
	if (index == null)
		index = (SimpleLuceneIndex) context.getAttribute("index");
	if (adn_to_nsdl_file == null)
		adn_to_nsdl_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("adn-to-nsdl-dc-xsl"));
	if (namespace_out_file == null)
		namespace_out_file = new File(((String) context.getAttribute("xslFilesDirecoryPath")) +
			"/" + context.getInitParameter("namespace-out-xsl"));
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:11,代码来源:ADNToNSDLDCFormatConverter.java

示例11: getJournalFromContext

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public static Journal getJournalFromContext(ServletContext context, String jid)
    throws IOException {
  JournalNode jn = (JournalNode)context.getAttribute(JN_ATTRIBUTE_KEY);
  return jn.getOrCreateJournal(jid);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:6,代码来源:JournalNodeHttpServer.java

示例12: HybridRecomDatasetsResource

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public HybridRecomDatasetsResource(@Context ServletContext sc) {
  this.mEngine = (MudrodEngine) sc.getAttribute("MudrodInstance");
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:4,代码来源:HybridRecomDatasetsResource.java

示例13: doFilter

import javax.servlet.ServletContext; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
    ServletContext servletContext = filterConfig.getServletContext();

    Container container = (Container) servletContext.getAttribute(Container.class.getName());
    if (container == null)
    {
        log.error("DwrWebContextFilter can not find ServletContext attribute for the DWR Container. Is DwrServlet configured in this web-application?");
    }

    ServletConfig servletConfig = (ServletConfig) servletContext.getAttribute(ServletConfig.class.getName());
    if (servletConfig == null)
    {
        log.error("DwrWebContextFilter can not find ServletContext attribute for the ServletConfig.");
    }

    WebContextBuilder webContextBuilder = (WebContextBuilder) servletContext.getAttribute(WebContextBuilder.class.getName());
    if (webContextBuilder == null)
    {
        log.error("DwrWebContextFilter can not find ServletContext attribute for the WebContextBuilder. WebContext will not be available.");
    }
    else
    {
        try
        {
            webContextBuilder.set((HttpServletRequest) request, (HttpServletResponse) response, servletConfig, servletContext, container);

            // It is totally legitimate for a servlet to be unavailable
            // (e.g. Spring DwrController)
            HttpServlet servlet = (HttpServlet) servletContext.getAttribute(HttpServlet.class.getName());
            if (servlet != null)
            {
                ServletLoggingOutput.setExecutionContext(servlet);
            }

            chain.doFilter(request, response);
        }
        finally
        {
            webContextBuilder.unset();
            ServletLoggingOutput.unsetExecutionContext();
        }
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:45,代码来源:DwrWebContextFilter.java

示例14: doListCollections

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 *  Handles a request to get a the available collections. <p>
 *
 *  Error Exception Conditions: <br>
 *  badArgument - The request includes illegal arguments.
 *
 * @param  request        The HTTP request
 * @param  response       The HTTP response
 * @param  rm             The RepositoryManager used
 * @param  df             The bean
 * @param  mapping        ActionMapping used
 * @return                An ActionForward to the JSP page that will handle the response
 * @exception  Exception  If error.
 */
protected ActionForward doListCollections(
                                          HttpServletRequest request,
                                          HttpServletResponse response,
                                          RepositoryManager rm,
                                          DDSServicesForm df,
                                          ActionMapping mapping)
	 throws Exception {

	ServletContext context = servlet.getServletContext();

	// If a different vocabInterface is requested, return it instead of the cache
	String vocabInterface = request.getParameter("vocabInterface");
	if (vocabInterface != null) {
		if (!vocabInterface.equals("dds.descr.en-us")) {
			df.setVocabInterface(vocabInterface);
			context.removeAttribute(getListCollectionsCacheKey());
		}
	}

	// Return the cached response if nothing has changed, otherwise update the cache
	if (rm.getSetStatusModifiedTime() > setStatusModifiedTime || rm.getIndexLastModifiedCount() > indexLastModifiedCount) {
		context.removeAttribute(getListCollectionsCacheKey());
		setStatusModifiedTime = rm.getSetStatusModifiedTime();
		prtln("removing coll cache key: " + getListCollectionsCacheKey());
		indexLastModifiedCount = rm.getIndexLastModifiedCount();
	}
	else if (context.getAttribute(getListCollectionsCacheKey()) != null) {
		// If nothing has changed and we've already got a cache, return it...
		return mapping.findForward("ddsservices.ListCollections");
	}

	// Records in the 'collect' collection are those that the Repository configures as collections:
	String query = "collection:0collect";

	// Sort by short title:
	Sort sortBy = new Sort( new SortField("/key//collectionRecord/general/shortTitle", SortField.STRING, false) );	
	
	ResultDocList results = rm.getIndex().searchDocs(query,sortBy);
	
	/* if (results != null) {
		Collections.sort(results, new LuceneFieldComparator("shorttitle", LuceneFieldComparator.ASCENDING));
	} */

	df.setResults(results);

	// Set up vocab
	//System.out.println("setting collection field...");
	df.setField("dlese_collect", "key");

	return mapping.findForward("ddsservices.ListCollections");
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:66,代码来源:DDSServicesAction.java

示例15: userHasAdministratorAccess

import javax.servlet.ServletContext; //导入方法依赖的package包/类
/**
 * Get the admin ACLs from the given ServletContext and check if the given
 * user is in the ACL.
 *
 * @param servletContext the context containing the admin ACL.
 * @param remoteUser the remote user to check for.
 * @return true if the user is present in the ACL, false if no ACL is set or
 *         the user is not present
 */
public static boolean userHasAdministratorAccess(ServletContext servletContext,
    String remoteUser) {
  AccessControlList adminsAcl = (AccessControlList) servletContext
      .getAttribute(ADMINS_ACL);
  UserGroupInformation remoteUserUGI =
      UserGroupInformation.createRemoteUser(remoteUser);
  return adminsAcl != null && adminsAcl.isUserAllowed(remoteUserUGI);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:HttpServer2.java


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