我的web.xml中的侦听器有什么问题? [英] What's wrong with my listener in my web.xml?

查看:177
本文介绍了我的web.xml中的侦听器有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将JBoss 4.22与portlet一起使用.当listener标记不在web.xml中时,将加载portlet,但不会(显然)不会调用listener sessionDestroyed().添加后,portlet不会被加载,也不会有任何异常或日志消息.我应该注意任何陷阱吗?

We're using JBoss 4.22 with portlets. When the listener tag is not in the web.xml the portlet loads, but the listener sessionDestroyed() is never called (obviously). When added the portlet isn't loaded, and there aren't any exceptions or log messages. Are there any gotchas I should be aware of?

   <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
             version="2.4">


           <!-- Listeners used by application -->
        <listener>
            <listener-class>listenerpackage.MyClassThatImplementsHttpSessionListener</listener-class>
        </listener>
    ...Other tags...
    </web-app>

作为对评论的答复,我一直在通过代码查找问题点.我的侦听器的构造函数确实存在一些可能的麻烦.通常(不是作为侦听器),实例将由相关的Portlet的实例(将侦听器添加到web.xml时不加载的实例)构造而成.我是否仍然可以期望这种情况还是容器本身会创建一个实例?

In reply to the comments I have been looking through the code to find trouble spots. My Listener's constructor does have some possible trouble. Normally (not as listener) an instance would be made by the relevant portlet's (the one that isn't loaded when the listener is added to the web.xml) constructor. Can I still expect this to be the case or does the container create a instance itself?

推荐答案

问题是,在部署文档中声明的侦听器将在加载该文档时实例化.我的课程被设计为由Portlet实例化,因此所需的信息不可用.

The problem is that listeners declared in the deployment document are instantiated when that document is loaded. My class was designed to be instantiated by the portlet so needed info wasn't available.

一种解决方案是使用 HttpSession 绑定监听器,并将该类作为属性添加到会话中.然后,当会话无效时,将调用unbound(). :)

A solution is to use an HttpSessionBindingListener and adding the class as an attribute to the session. Then the unbound() is called when the session invalidates. :)

这篇关于我的web.xml中的侦听器有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆