本文整理匯總了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);
}
示例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;
}
示例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();
}
}
示例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"));
}
示例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} ");
}
示例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);
}
}
示例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;
}
示例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;
}
示例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"));
}
示例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);
}
示例12: HybridRecomDatasetsResource
import javax.servlet.ServletContext; //導入方法依賴的package包/類
public HybridRecomDatasetsResource(@Context ServletContext sc) {
this.mEngine = (MudrodEngine) sc.getAttribute("MudrodInstance");
}
示例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();
}
}
}
示例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");
}
示例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);
}