本文整理了Java中javax.servlet.ServletContext.getServletContextName()
方法的一些代码示例,展示了ServletContext.getServletContextName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletContext.getServletContextName()
方法的具体详情如下:
包路径:javax.servlet.ServletContext
类名称:ServletContext
方法名:getServletContextName
[英]Returns the name of this web application corresponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.
[中]返回与此ServletContext对应的此web应用程序的名称,该名称由display name元素在此web应用程序的部署描述符中指定。
代码示例来源:origin: igniterealtime/Openfire
@Override
public String getServletContextName()
{
return proxy.getServletContextName();
}
代码示例来源:origin: org.freemarker/freemarker
/**
* Show class name and some details that are useful in template-not-found errors.
*
* @since 2.3.21
*/
@Override
public String toString() {
return TemplateLoaderUtils.getClassNameForToString(this)
+ "(subdirPath=" + StringUtil.jQuote(subdirPath)
+ ", servletContext={contextPath=" + StringUtil.jQuote(getContextPath())
+ ", displayName=" + StringUtil.jQuote(servletContext.getServletContextName()) + "})";
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
@Override
public String getServletContextName() {
return _servletContext.getServletContextName();
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
public String getServletContextName() {
return _servletContext.getServletContextName();
}
代码示例来源:origin: javamelody/javamelody
serverInfo = servletContext.getServerInfo();
contextPath = Parameters.getContextPath(servletContext);
contextDisplayName = servletContext.getServletContextName();
webappVersion = MavenArtifact.getWebappVersion();
代码示例来源:origin: camunda/camunda-bpm-platform
public void contextInitialized(ServletContextEvent sce) {
servletContext = sce.getServletContext();
servletContextPath = servletContext.getContextPath();
servletContextName = sce.getServletContext().getServletContextName();
processApplicationClassloader = initProcessApplicationClassloader(sce);
// perform lifecycle start
deploy();
}
代码示例来源:origin: haraldk/TwelveMonkeys
/**
* Gets the servlet or filter name from the config.
*
* @return the servlet or filter name
*/
public final String getName() {
switch (type) {
case ServletConfig:
return servletConfig.getServletName();
case FilterConfig:
return filterConfig.getFilterName();
case ServletContext:
return servletContext.getServletContextName();
default:
throw new IllegalStateException();
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public void contextInitialized(ServletContextEvent sce) {
servletContext = sce.getServletContext();
servletContextPath = servletContext.getContextPath();
servletContextName = sce.getServletContext().getServletContextName();
processApplicationClassloader = initProcessApplicationClassloader(sce);
// perform lifecycle start
deploy();
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
public void throwHotDeployException(
HotDeployEvent event, String msg, Throwable t)
throws HotDeployException {
ServletContext servletContext = event.getServletContext();
String servletContextName = servletContext.getServletContextName();
throw new HotDeployException(msg + servletContextName, t);
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
portalDestroy();
if (_classLoaderRegistered) {
ServletContextClassLoaderPool.unregister(
servletContext.getServletContextName());
}
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
servletContext = servletContextEvent.getServletContext();
Thread currentThread = Thread.currentThread();
pluginClassLoader = currentThread.getContextClassLoader();
String servletContextName = servletContext.getServletContextName();
if (ServletContextClassLoaderPool.getClassLoader(servletContextName) ==
null) {
ServletContextClassLoaderPool.register(
servletContextName, pluginClassLoader);
_classLoaderRegistered = true;
}
servletContext.setAttribute(PLUGIN_CLASS_LOADER, pluginClassLoader);
ServletContextPool.put(servletContextName, servletContext);
registerPortalLifecycle();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-web
private void initializeNonJndi(final String location) {
if (this.name == null) {
this.name = this.servletContext.getServletContextName();
LOGGER.debug("Using the servlet context name \"{}\".", this.name);
}
if (this.name == null) {
this.name = this.servletContext.getContextPath();
LOGGER.debug("Using the servlet context context-path \"{}\".", this.name);
}
if (this.name == null && location == null) {
LOGGER.error("No Log4j context configuration provided. This is very unusual.");
this.name = new SimpleDateFormat("yyyyMMdd_HHmmss.SSS").format(new Date());
}
if (location != null && location.contains(",")) {
final List<URI> uris = getConfigURIs(location);
this.loggerContext = Configurator.initialize(this.name, this.getClassLoader(), uris, this.servletContext);
return;
}
final URI uri = getConfigURI(location);
this.loggerContext = Configurator.initialize(this.name, this.getClassLoader(), uri, this.servletContext);
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
protected ResourceBundleLoader getResourceBundleLoader() {
if (_servletContext != null) {
return ResourceBundleLoaderUtil.
getResourceBundleLoaderByServletContextName(
_servletContext.getServletContextName());
}
return new AggregateResourceBundleLoader(
new ClassResourceBundleLoader("content.Language", getClass()),
ResourceBundleLoaderUtil.getPortalResourceBundleLoader());
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testNotFound() throws ServletException, IOException {
StaticContentServlet servlet = new StaticContentServlet();
ServletContext context = mock(ServletContext.class);
when(context.getServletContextName()).thenReturn("foo");
when(context.getMimeType(anyString())).thenReturn("image/jpeg");
ServletConfig config = mock(ServletConfig.class);
when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root")));
when(config.getInitParameter("root")).thenReturn(getFileSystemRoot());
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getMethod()).thenReturn("GET");
when(request.getPathInfo()).thenReturn("/missing.jpg");
when(request.getRequestURI()).thenReturn("/foo/missing.jpg");
when(request.getContextPath()).thenReturn("/foo");
HttpServletResponse response = mock(HttpServletResponse.class);
servlet.service(request, response);
verify(response).sendError(HttpServletResponse.SC_NOT_FOUND, "/foo/missing.jpg");
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testDirectoryListingForbidden() throws ServletException, IOException {
StaticContentServlet servlet = new StaticContentServlet();
ServletContext context = mock(ServletContext.class);
when(context.getServletContextName()).thenReturn("foo");
when(context.getMimeType(anyString())).thenReturn("image/png");
ServletConfig config = mock(ServletConfig.class);
when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root")));
when(config.getInitParameter("root")).thenReturn(getFileSystemRoot());
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getMethod()).thenReturn("GET");
when(request.getPathInfo()).thenReturn("/"); // Attempt directory listing
when(request.getRequestURI()).thenReturn("/foo/"); // Attempt directory listing
when(request.getContextPath()).thenReturn("/foo");
ServletOutputStream stream = mock(ServletOutputStream.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getOutputStream()).thenReturn(stream);
servlet.service(request, response);
verify(response).sendError(HttpServletResponse.SC_FORBIDDEN, "/foo/");
}
代码示例来源:origin: haraldk/TwelveMonkeys
when(context.getServletContextName()).thenReturn("foo");
when(context.getMimeType(anyString())).thenReturn("image/png");
代码示例来源:origin: haraldk/TwelveMonkeys
when(context.getServletContextName()).thenReturn("foo");
when(context.getMimeType(anyString())).thenReturn("image/png");
代码示例来源:origin: haraldk/TwelveMonkeys
when(context.getServletContextName()).thenReturn("foo");
when(context.getMimeType(anyString())).thenReturn("text/plain");
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testGetNotModified() throws ServletException, IOException {
StaticContentServlet servlet = new StaticContentServlet();
ServletContext context = mock(ServletContext.class);
when(context.getServletContextName()).thenReturn("foo");
when(context.getMimeType(anyString())).thenReturn("image/png");
ServletConfig config = mock(ServletConfig.class);
when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root")));
when(config.getInitParameter("root")).thenReturn(getFileSystemRoot());
when(config.getServletContext()).thenReturn(context);
servlet.init(config);
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getMethod()).thenReturn("GET");
when(request.getPathInfo()).thenReturn(IMAGE_RESOURCE);
when(request.getRequestURI()).thenReturn("/foo" + IMAGE_RESOURCE);
when(request.getContextPath()).thenReturn("/foo");
when(request.getDateHeader("If-Modified-Since")).thenReturn(getResourceAsFile(IMAGE_RESOURCE).lastModified());
ServletOutputStream stream = mock(ServletOutputStream.class);
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getOutputStream()).thenReturn(stream);
servlet.service(request, response);
verify(response).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
verifyZeroInteractions(stream);
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
@Override
protected void fireUndeployEvent() {
if (_servletContextListeners != null) {
ServletContextEvent servletContextEvent = new ServletContextEvent(
servletContext);
for (ServletContextListener servletContextListener :
_servletContextListeners) {
try {
servletContextListener.contextDestroyed(
servletContextEvent);
}
catch (Throwable t) {
String className = ClassUtil.getClassName(
servletContextListener.getClass());
_log.error(
StringBundler.concat(
className, " is unable to process a context ",
"destroyed event for ",
servletContext.getServletContextName()),
t);
}
}
}
super.fireUndeployEvent();
}
内容来源于网络,如有侵权,请联系作者删除!