本文整理汇总了Java中javax.servlet.Servlet类的典型用法代码示例。如果您正苦于以下问题:Java Servlet类的具体用法?Java Servlet怎么用?Java Servlet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Servlet类属于javax.servlet包,在下文中一共展示了Servlet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deallocate
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* Return this previously allocated servlet to the pool of available
* instances. If this servlet class does not implement SingleThreadModel, no
* action is actually required.
*
* @param servlet
* The servlet to be returned
*
* @exception ServletException
* if a deallocation error occurs
*/
@Override
public void deallocate(Servlet servlet) throws ServletException {
// If not SingleThreadModel, no action is required
if (!singleThreadModel) {
countAllocated.decrementAndGet();
return;
}
// Unlock and free this instance
synchronized (instancePool) {
countAllocated.decrementAndGet();
instancePool.push(servlet);
instancePool.notify();
}
}
示例2: onServletStop
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* onServletStop
*
* @param args
*/
@Override
public void onServletStop(Object... args) {
StandardWrapper sw = (StandardWrapper) args[0];
Servlet servlet = (Servlet) args[1];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.BEFORE_SERVLET_DESTROY);
context.put(InterceptConstants.SERVLET_INSTANCE, servlet);
/**
* NOTE: spring boot rewrite the tomcat webappclassloader, makes the addURL for nothing, then we can't do
* anything on this we may use its webappclassloader's parent as the classloader
*/
context.put(InterceptConstants.WEBAPPLOADER, Thread.currentThread().getContextClassLoader().getParent());
context.put(InterceptConstants.CONTEXTPATH, sw.getServletContext().getContextPath());
iSupport.doIntercept(context);
}
示例3: getServlet
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* @deprecated As of Java Servlet API 2.1, with no direct replacement.
*/
@Override
@Deprecated
public Servlet getServlet(String name)
throws ServletException {
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
return (Servlet) invokeMethod(context, "getServlet",
new Object[]{name});
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
if (t instanceof ServletException) {
throw (ServletException) t;
}
return null;
}
} else {
return context.getServlet(name);
}
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:23,代码来源:ApplicationContextFacade.java
示例4: doPrivileged
import javax.servlet.Servlet; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked") // doPrivileged() returns the correct type
public <T extends Servlet> T createServlet(Class<T> c) throws ServletException {
if (SecurityUtil.isPackageProtectionEnabled()) {
try {
return (T) invokeMethod(context, "createServlet", new Object[] { c });
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
if (t instanceof ServletException) {
throw (ServletException) t;
}
return null;
}
} else {
return context.createServlet(c);
}
}
示例5: deallocate
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* Return this previously allocated servlet to the pool of available
* instances. If this servlet class does not implement SingleThreadModel,
* no action is actually required.
*
* @param servlet The servlet to be returned
*
* @exception ServletException if a deallocation error occurs
*/
@Override
public void deallocate(Servlet servlet) throws ServletException {
// If not SingleThreadModel, no action is required
if (!singleThreadModel) {
countAllocated.decrementAndGet();
return;
}
// Unlock and free this instance
synchronized (instancePool) {
countAllocated.decrementAndGet();
instancePool.push(servlet);
instancePool.notify();
}
}
示例6: fireInstanceEvent
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* Notify all lifecycle event listeners that a particular event has
* occurred for this Container. The default implementation performs
* this notification synchronously using the calling thread.
*
* @param type Event type
* @param servlet The relevant Servlet for this event
* @param request The servlet request we are processing
* @param response The servlet response we are processing
* @param exception Exception that occurred
*/
public void fireInstanceEvent(String type, Servlet servlet,
ServletRequest request,
ServletResponse response,
Throwable exception) {
if (listeners.length == 0)
return;
InstanceEvent event = new InstanceEvent(wrapper, servlet, type,
request, response, exception);
InstanceListener interested[] = listeners;
for (int i = 0; i < interested.length; i++)
interested[i].instanceEvent(event);
}
示例7: InstanceEvent
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* Construct a new InstanceEvent with the specified parameters. This
* constructor is used for processing servlet lifecycle events.
*
* @param wrapper Wrapper managing this servlet instance
* @param servlet Servlet instance for which this event occurred
* @param type Event type (required)
* @param exception Exception that occurred
*/
public InstanceEvent(Wrapper wrapper, Servlet servlet, String type,
Throwable exception) {
super(wrapper);
this.wrapper = wrapper;
this.filter = null;
this.servlet = servlet;
this.type = type;
this.exception = exception;
}
示例8: ServletInfo
import javax.servlet.Servlet; //导入依赖的package包/类
public ServletInfo(final String name, final Class<? extends Servlet> servletClass) {
if (name == null) {
throw UndertowServletMessages.MESSAGES.paramCannotBeNull("name");
}
if (servletClass == null) {
throw UndertowServletMessages.MESSAGES.paramCannotBeNull("servletClass", "Servlet", name);
}
if (!Servlet.class.isAssignableFrom(servletClass)) {
throw UndertowServletMessages.MESSAGES.servletMustImplementServlet(name, servletClass);
}
try {
final Constructor<? extends Servlet> ctor = servletClass.getDeclaredConstructor();
ctor.setAccessible(true);
this.instanceFactory = new ConstructorInstanceFactory(ctor);
this.name = name;
this.servletClass = servletClass;
} catch (NoSuchMethodException e) {
throw UndertowServletMessages.MESSAGES.componentMustHaveDefaultConstructor("Servlet", servletClass);
}
}
示例9: addService
import javax.servlet.Servlet; //导入依赖的package包/类
public static void addService(Class<? extends Servlet> service) {
try {
APIHandler handler = (APIHandler) service.newInstance();
services.add(service);
serviceMap.put(handler.getAPIName(), handler);
} catch (InstantiationException | IllegalAccessException e) {
Data.logger.warn("", e);
}
}
示例10: addServlet
import javax.servlet.Servlet; //导入依赖的package包/类
@Override
public ServletRegistration.Dynamic addServlet(String servletName,
Class<? extends Servlet> servletClass) {
if (SecurityUtil.isPackageProtectionEnabled()) {
return (ServletRegistration.Dynamic) doPrivileged("addServlet",
new Class[]{String.class, Class.class},
new Object[]{servletName, servletClass});
} else {
return context.addServlet(servletName, servletClass);
}
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:12,代码来源:ApplicationContextFacade.java
示例11: thrift
import javax.servlet.Servlet; //导入依赖的package包/类
@Bean
Servlet thrift(ThriftCodecManager thriftCodecManager, TProtocolFactory protocolFactory, TCalculatorService calculatorService) {
ThriftServiceProcessor processor = new ThriftServiceProcessor(thriftCodecManager, Arrays.<ThriftEventHandler>asList(), calculatorService);
return new TServlet(
NiftyProcessorAdapters.processorToTProcessor(processor),
protocolFactory,
protocolFactory
);
}
示例12: InstanceEvent
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* Construct a new InstanceEvent with the specified parameters. This
* constructor is used for processing servlet processing events.
*
* @param wrapper Wrapper managing this servlet instance
* @param servlet Servlet instance for which this event occurred
* @param type Event type (required)
* @param request Servlet request we are processing
* @param response Servlet response we are processing
* @param exception Exception that occurred
*/
public InstanceEvent(Wrapper wrapper, Servlet servlet, String type,
ServletRequest request, ServletResponse response,
Throwable exception) {
super(wrapper);
this.filter = null;
this.servlet = servlet;
this.type = type;
this.request = request;
this.response = response;
this.exception = exception;
}
示例13: internalGetPageContext
import javax.servlet.Servlet; //导入依赖的package包/类
private PageContext internalGetPageContext(Servlet servlet, ServletRequest request,
ServletResponse response, String errorPageURL, boolean needsSession,
int bufferSize, boolean autoflush) {
try {
PageContext pc;
if (USE_POOL) {
PageContextPool pool = localPool.get();
if (pool == null) {
pool = new PageContextPool();
localPool.set(pool);
}
pc = pool.get();
if (pc == null) {
pc = new PageContextImpl();
}
} else {
pc = new PageContextImpl();
}
pc.initialize(servlet, request, response, errorPageURL,
needsSession, bufferSize, autoflush);
return pc;
} catch (Throwable ex) {
ExceptionUtils.handleThrowable(ex);
if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
}
log.fatal("Exception initializing page context", ex);
return null;
}
}
示例14: doAsPrivilege
import javax.servlet.Servlet; //导入依赖的package包/类
/**
* Perform work as a particular </code>Subject</code>. Here the work
* will be granted to a <code>null</code> subject.
*
* @param methodName the method to apply the security restriction
* @param targetObject the <code>Servlet</code> on which the method will
* be called.
* @param targetParameterTypes <code>Class</code> array used to instantiate a
* <code>Method</code> object.
* @param targetArguments <code>Object</code> array contains the
* runtime parameters instance.
* @param principal the <code>Principal</code> to which the security
* privilege apply..
*/
public static void doAsPrivilege(final String methodName,
final Servlet targetObject,
final Class<?>[] targetParameterTypes,
final Object[] targetArguments,
Principal principal)
throws java.lang.Exception{
// CometProcessor instances must not be cached as Servlet or
// NoSuchMethodException will be thrown.
Class<? extends Servlet> targetType =
targetObject instanceof CometProcessor ? CometProcessor.class : Servlet.class;
Method method = null;
Method[] methodsCache = classCache.get(Servlet.class);
if(methodsCache == null) {
method = createMethodAndCacheIt(methodsCache,
targetType,
methodName,
targetParameterTypes);
} else {
method = findMethod(methodsCache, methodName);
if (method == null) {
method = createMethodAndCacheIt(methodsCache,
targetType,
methodName,
targetParameterTypes);
}
}
execute(method, targetObject, targetArguments, principal);
}
示例15: ExistingStandardWrapper
import javax.servlet.Servlet; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public ExistingStandardWrapper( Servlet existing ) {
this.existing = existing;
if (existing instanceof javax.servlet.SingleThreadModel) {
singleThreadModel = true;
instancePool = new Stack<Servlet>();
}
}