本文整理汇总了Java中org.apache.catalina.Context.getServletContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getServletContext方法的具体用法?Java Context.getServletContext怎么用?Java Context.getServletContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.Context
的用法示例。
在下文中一共展示了Context.getServletContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebappServiceLoader
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Construct a loader to load services from a ServletContext.
*
* @param context the context to use
*/
public WebappServiceLoader(Context context) {
this.context = context;
this.servletContext = context.getServletContext();
String containerSciFilter = context.getContainerSciFilter();
if (containerSciFilter != null && containerSciFilter.length() > 0) {
containerSciFilterPattern = Pattern.compile(containerSciFilter);
} else {
containerSciFilterPattern = null;
}
}
示例2: getServletContext
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Return the ServletContext to which this session belongs.
*/
@Override
public ServletContext getServletContext() {
if (manager == null) {
return null;
}
Context context = (Context) manager.getContainer();
return context.getServletContext();
}
示例3: testBug54240
import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testBug54240() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
tomcat.start();
ServletContext context = ctx.getServletContext();
TagPluginManager manager = new TagPluginManager(context);
Node.Nodes nodes = new Node.Nodes();
Node.CustomTag c = new Node.CustomTag("test:ATag", "test", "ATag",
"http://tomcat.apache.org/jasper", null, null, null, null, null,
new TagFileInfo("ATag", "http://tomcat.apache.org/jasper",
tagInfo));
c.setTagHandlerClass(TesterTag.class);
nodes.add(c);
manager.apply(nodes, null, null);
Node n = nodes.getNode(0);
Assert.assertNotNull(n);
Assert.assertTrue(n instanceof Node.CustomTag);
Node.CustomTag t = (Node.CustomTag)n;
Assert.assertNotNull(t.getAtSTag());
Node.Nodes sTag = c.getAtSTag();
Node scriptlet = sTag.getNode(0);
Assert.assertNotNull(scriptlet);
Assert.assertTrue(scriptlet instanceof Node.Scriptlet);
Node.Scriptlet s = (Node.Scriptlet)scriptlet;
Assert.assertEquals("//Just a comment", s.getText());
}
示例4: getServletContext
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Return the ServletContext to which this session belongs.
*/
public ServletContext getServletContext() {
if (manager == null)
return (null);
Context context = (Context) manager.getContainer();
if (context == null)
return (null);
else
return (context.getServletContext());
}
示例5: getContext
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Return a <code>ServletContext</code> object that corresponds to a
* specified URI on the server. This method allows servlets to gain
* access to the context for various parts of the server, and as needed
* obtain <code>RequestDispatcher</code> objects or resources from the
* context. The given path must be absolute (beginning with a "/"),
* and is interpreted based on our virtual host's document root.
*
* @param uri Absolute URI of a resource on the server
*/
public ServletContext getContext(String uri) {
// Validate the format of the specified argument
if ((uri == null) || (!uri.startsWith("/")))
return (null);
// Return the current context if requested
String contextPath = context.getPath();
if (!contextPath.endsWith("/"))
contextPath = contextPath + "/";
if ((contextPath.length() > 0) && (uri.startsWith(contextPath))) {
return (this);
}
// Return other contexts only if allowed
if (!context.getCrossContext())
return (null);
try {
Host host = (Host) context.getParent();
Context child = host.map(uri);
if (child != null)
return (child.getServletContext());
else
return (null);
} catch (Throwable t) {
return (null);
}
}
示例6: WebappServiceLoader
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Construct a loader to load services from a ServletContext.
*
* @param context
* the context to use
*/
public WebappServiceLoader(Context context) {
this.context = context;
this.servletContext = context.getServletContext();
String containerSciFilter = context.getContainerSciFilter();
if (containerSciFilter != null && containerSciFilter.length() > 0) {
containerSciFilterPattern = Pattern.compile(containerSciFilter);
} else {
containerSciFilterPattern = null;
}
}
示例7: getServletContext
import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
* Return the ServletContext to which this session belongs.
*/
@Override
public ServletContext getServletContext() {
if (manager == null) {
return null;
}
Context context = (Context) manager.getContainer();
return context.getServletContext();
}
示例8: testBug54239
import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testBug54239() throws Exception {
Tomcat tomcat = getTomcatInstance();
File appDir = new File("test/webapp-3.0");
Context ctx = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
tomcat.start();
ServletContext context = ctx.getServletContext();
ELInterpreter interpreter =
ELInterpreterFactory.getELInterpreter(context);
Assert.assertNotNull(interpreter);
Assert.assertTrue(interpreter instanceof DefaultELInterpreter);
context.removeAttribute(ELInterpreter.class.getName());
context.setAttribute(ELInterpreter.class.getName(),
SimpleELInterpreter.class.getName());
interpreter = ELInterpreterFactory.getELInterpreter(context);
Assert.assertNotNull(interpreter);
Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
context.removeAttribute(ELInterpreter.class.getName());
SimpleELInterpreter simpleInterpreter = new SimpleELInterpreter();
context.setAttribute(ELInterpreter.class.getName(), simpleInterpreter);
interpreter = ELInterpreterFactory.getELInterpreter(context);
Assert.assertNotNull(interpreter);
Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
Assert.assertTrue(interpreter == simpleInterpreter);
context.removeAttribute(ELInterpreter.class.getName());
ctx.stop();
ctx.addApplicationListener(Bug54239Listener.class.getName());
ctx.start();
interpreter = ELInterpreterFactory.getELInterpreter(ctx.getServletContext());
Assert.assertNotNull(interpreter);
Assert.assertTrue(interpreter instanceof SimpleELInterpreter);
}