本文整理汇总了Java中javax.servlet.ServletRequestAttributeListener类的典型用法代码示例。如果您正苦于以下问题:Java ServletRequestAttributeListener类的具体用法?Java ServletRequestAttributeListener怎么用?Java ServletRequestAttributeListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServletRequestAttributeListener类属于javax.servlet包,在下文中一共展示了ServletRequestAttributeListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyAttributeRemoved
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
/**
* Notify interested listeners that attribute has been removed.
*/
private void notifyAttributeRemoved(String name, Object value) {
Object listeners[] = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0)) {
return;
}
ServletRequestAttributeEvent event =
new ServletRequestAttributeEvent(context.getServletContext(),
getRequest(), name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletRequestAttributeListener)) {
continue;
}
ServletRequestAttributeListener listener =
(ServletRequestAttributeListener) listeners[i];
try {
listener.attributeRemoved(event);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
// Error valve will pick this exception up and display it to user
attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
}
}
}
示例2: notifyAttributeRemoved
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
/**
* Notify interested listeners that attribute has been removed.
*/
private void notifyAttributeRemoved(String name, Object value) {
Object listeners[] = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0)) {
return;
}
ServletRequestAttributeEvent event = new ServletRequestAttributeEvent(context.getServletContext(), getRequest(),
name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletRequestAttributeListener)) {
continue;
}
ServletRequestAttributeListener listener = (ServletRequestAttributeListener) listeners[i];
try {
listener.attributeRemoved(event);
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
// Error valve will pick this exception up and display it to
// user
attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
}
}
}
示例3: init
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
/**
* Init method called by the main servlet when the wrapping servlet is initialized. This means that the context is
* taken into service by the system.
*
* @param parent The parent servlet context. Just for some delegation actions
*/
void init(ServletContext parent) {
// Set up the tracking of event listeners.
BundleContext bc = getOwner().getBundleContext();
delegate = parent;
Collection<Class<? extends EventListener>> toTrack = Arrays.asList(HttpSessionListener.class,
ServletRequestListener.class, HttpSessionAttributeListener.class, ServletRequestAttributeListener.class,
ServletContextListener.class);
Collection<String> objectFilters = toTrack.stream().
map((c) -> "(" + Constants.OBJECTCLASS + "=" + c.getName() + ")").collect(Collectors.toList());
String filterString = "|" + String.join("", objectFilters);
eventListenerTracker = startTracking(filterString,
new Tracker<EventListener, EventListener>(bc, getContextPath(), (e) -> e, (e) -> { /* No destruct */}));
// Initialize the servlets.
ServletContextEvent event = new ServletContextEvent(this);
call(ServletContextListener.class, (l) -> l.contextInitialized(event));
servlets.values().forEach((s) -> init(s));
// And the filters.
filters.values().forEach((f) -> init(f));
// Set up the tracking of servlets and filters.
servletTracker = startTracking(Constants.OBJECTCLASS + "=" + Servlet.class.getName(),
new Tracker<Servlet, String>(bc, getContextPath(), this::addServlet, this::removeServlet));
filterTracker = startTracking(Constants.OBJECTCLASS + "=" + Filter.class.getName(),
new Tracker<Filter, String>(bc, getContextPath(), this::addFilter, this::removeFilter));
}
示例4: isWeb
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
private static boolean isWeb(final Class<?> beanClass) {
if (Servlet.class.isAssignableFrom(beanClass)
|| Filter.class.isAssignableFrom(beanClass)) {
return true;
}
if (EventListener.class.isAssignableFrom(beanClass)) {
return HttpSessionAttributeListener.class.isAssignableFrom(beanClass)
|| ServletContextListener.class.isAssignableFrom(beanClass)
|| ServletRequestListener.class.isAssignableFrom(beanClass)
|| ServletContextAttributeListener.class.isAssignableFrom(beanClass)
|| HttpSessionListener.class.isAssignableFrom(beanClass)
|| HttpSessionBindingListener.class.isAssignableFrom(beanClass)
|| HttpSessionActivationListener.class.isAssignableFrom(beanClass)
|| HttpSessionIdListener.class.isAssignableFrom(beanClass)
|| ServletRequestAttributeListener.class.isAssignableFrom(beanClass);
}
return false;
}
示例5: addListener
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
@Override
public <T extends EventListener> void addListener(T t) {
if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
throw new IllegalStateException(
sm.getString("applicationContext.addListener.ise",
getContextPath()));
}
boolean match = false;
if (t instanceof ServletContextAttributeListener ||
t instanceof ServletRequestListener ||
t instanceof ServletRequestAttributeListener ||
t instanceof HttpSessionAttributeListener) {
context.addApplicationEventListener(t);
match = true;
}
if (t instanceof HttpSessionListener
|| (t instanceof ServletContextListener &&
newServletContextListenerAllowed)) {
// Add listener directly to the list of instances rather than to
// the list of class names.
context.addApplicationLifecycleListener(t);
match = true;
}
if (match) return;
if (t instanceof ServletContextListener) {
throw new IllegalArgumentException(sm.getString(
"applicationContext.addListener.iae.sclNotAllowed",
t.getClass().getName()));
} else {
throw new IllegalArgumentException(sm.getString(
"applicationContext.addListener.iae.wrongType",
t.getClass().getName()));
}
}
示例6: addListener
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
@Override
public <T extends EventListener> void addListener(T t) {
if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
throw new IllegalStateException(sm.getString("applicationContext.addListener.ise", getContextPath()));
}
boolean match = false;
if (t instanceof ServletContextAttributeListener || t instanceof ServletRequestListener
|| t instanceof ServletRequestAttributeListener || t instanceof HttpSessionAttributeListener) {
context.addApplicationEventListener(t);
match = true;
}
if (t instanceof HttpSessionListener
|| (t instanceof ServletContextListener && newServletContextListenerAllowed)) {
// Add listener directly to the list of instances rather than to
// the list of class names.
context.addApplicationLifecycleListener(t);
match = true;
}
if (match)
return;
if (t instanceof ServletContextListener) {
throw new IllegalArgumentException(
sm.getString("applicationContext.addListener.iae.sclNotAllowed", t.getClass().getName()));
} else {
throw new IllegalArgumentException(
sm.getString("applicationContext.addListener.iae.wrongType", t.getClass().getName()));
}
}
示例7: loadListeners
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
private void loadListeners(WebAppConfiguration wac)
throws ClassNotFoundException, IllegalAccessException,
InstantiationException, WebAppConfigurationException {
for (WebAppListener listener : wac.getListeners()) {
String className = listener.getListenerClass();
Class<?> clazz = classLoader.loadClass(className);
Object obj = clazz.newInstance();
boolean used = false;
if (obj instanceof ServletContextAttributeListener) {
scaListeners.add((ServletContextAttributeListener) obj);
used = true;
}
if (obj instanceof ServletContextListener) {
scListeners.add((ServletContextListener) obj);
used = true;
}
if (obj instanceof ServletRequestListener) {
srListeners.add((ServletRequestListener) obj);
used = true;
}
if (obj instanceof ServletRequestAttributeListener) {
sraListeners.add((ServletRequestAttributeListener) obj);
used = true;
}
if (obj instanceof HttpSessionAttributeListener) {
sessionAttributeListeners.add((HttpSessionAttributeListener) obj);
used = true;
}
if (obj instanceof HttpSessionListener) {
sessionListeners.add((HttpSessionListener) obj);
used = true;
}
if (!used) {
throw new WebAppConfigurationException("Don't know what to do with '"
+ className + "'");
}
}
}
示例8: ServletRequestAttributeListenerWrapper
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
public ServletRequestAttributeListenerWrapper(
ServletRequest request,
ServletContext context,
ServletRequestAttributeListener listener) {
super(request);
this.context = context;
this.listener = listener;
}
示例9: addListenerInstance
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
private void addListenerInstance(final Object listenerInstance,
final List<ServletContextAttributeListener> contextAttributeListeners,
final List<ServletContextListener> contextListeners,
final List<ServletRequestAttributeListener> requestAttributeListeners,
final List<ServletRequestListener> requestListeners, final List<HttpSessionActivationListener> sessionActivationListeners,
final List<HttpSessionAttributeListener> sessionAttributeListeners, final List<HttpSessionListener> sessionListeners) {
if (listenerInstance instanceof ServletContextAttributeListener) {
contextAttributeListeners.add((ServletContextAttributeListener) listenerInstance);
}
if (listenerInstance instanceof ServletContextListener) {
contextListeners.add((ServletContextListener) listenerInstance);
}
if (listenerInstance instanceof ServletRequestAttributeListener) {
requestAttributeListeners.add((ServletRequestAttributeListener) listenerInstance);
}
if (listenerInstance instanceof ServletRequestListener) {
requestListeners.add((ServletRequestListener) listenerInstance);
}
if (listenerInstance instanceof HttpSessionActivationListener) {
sessionActivationListeners.add((HttpSessionActivationListener) listenerInstance);
}
if (listenerInstance instanceof HttpSessionAttributeListener) {
sessionAttributeListeners.add((HttpSessionAttributeListener) listenerInstance);
}
if (listenerInstance instanceof HttpSessionListener) {
sessionListeners.add((HttpSessionListener) listenerInstance);
}
}
示例10: attributeAdded
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
public void attributeAdded(final ServletRequestAttributeEvent srae)
{
final Iterator<ServletRequestAttributeListener> listeners = getContextListeners();
while (listeners.hasNext())
{
listeners.next().attributeAdded(srae);
}
}
示例11: attributeRemoved
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
public void attributeRemoved(final ServletRequestAttributeEvent srae)
{
final Iterator<ServletRequestAttributeListener> listeners = getContextListeners();
while (listeners.hasNext())
{
listeners.next().attributeRemoved(srae);
}
}
示例12: attributeReplaced
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
public void attributeReplaced(final ServletRequestAttributeEvent srae)
{
final Iterator<ServletRequestAttributeListener> listeners = getContextListeners();
while (listeners.hasNext())
{
listeners.next().attributeReplaced(srae);
}
}
示例13: removeAttribute
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
/**
* Remove the specified request attribute if it exists.
*
* @param name Name of the request attribute to remove
*/
public void removeAttribute(String name) {
Object value = null;
boolean found = false;
// Remove the specified attribute
// Check for read only attribute
// requests are per thread so synchronization unnecessary
if (readOnlyAttributes.containsKey(name)) {
return;
}
// Pass special attributes to the native layer
if (name.startsWith("org.apache.tomcat.")) {
coyoteRequest.getAttributes().remove(name);
}
found = attributes.containsKey(name);
if (found) {
value = attributes.get(name);
attributes.remove(name);
} else {
return;
}
// Notify interested application event listeners
Object listeners[] = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0))
return;
ServletRequestAttributeEvent event =
new ServletRequestAttributeEvent(context.getServletContext(),
getRequest(), name, value);
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof ServletRequestAttributeListener))
continue;
ServletRequestAttributeListener listener =
(ServletRequestAttributeListener) listeners[i];
try {
listener.attributeRemoved(event);
} catch (Throwable t) {
context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
// Error valve will pick this execption up and display it to user
attributes.put( Globals.EXCEPTION_ATTR, t );
}
}
}
示例14: servletRequestAttributeAdded
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
public void servletRequestAttributeAdded(final HttpServletRequest request, final String name, final Object value) {
final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value);
for (int i = 0; i < servletRequestAttributeListeners.length; ++i) {
this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeAdded(sre);
}
}
示例15: servletRequestAttributeRemoved
import javax.servlet.ServletRequestAttributeListener; //导入依赖的package包/类
public void servletRequestAttributeRemoved(final HttpServletRequest request, final String name, final Object value) {
final ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent(servletContext, request, name, value);
for (int i = 0; i < servletRequestAttributeListeners.length; ++i) {
this.<ServletRequestAttributeListener>get(servletRequestAttributeListeners[i]).attributeRemoved(sre);
}
}