从 Struts2 操作标签调用操作时出现 java.lang.StackOverflowError

发布于 2024-11-10 10:17:07 字数 4447 浏览 4 评论 0原文

我有 dccr.jsp 文件,它通过标签调用操作:

<s:action name="query-privilege" executeResult="false" var="privilege">
            <s:param name="moduleid">9</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">dccr</s:param>
</s:action>

我使用此操作来查询用户之间的模块权限,如下所示:

<s:if test="%{#privilege.allowable == false}">
       //do something
</s:if>

这是我的操作支持类:

    private String pagename;
    private String moduleid;
    private boolean allowable;
    private String privilege;
    private final UsertypeModuleDAO umodDao = (UsertypeModuleDAO) ServletActionContext.getServletContext().getAttribute("usermoduleDAO");

    //loggers, session properties etc.

@Action(value = "/query-privilege", results = {
        @Result(name = "SUCCESSdccr", location = "/dccr.jsp"),
        @Result(name = "ERROR", location = "../error/messages.jsp")
    })
    @Override
    public String execute() {
        try {
            char p = privilege.charAt(0);
            int i = Integer.parseInt(moduleid);
            allowable = queryPrivilege(i, p);
            logger.info(privilege+", "+moduleid+", "+ut.getUsertypeid()+", "+allowable);
            return SUCCESS + pagename;
        } catch (Exception e) {
            if (emps != null) {
                logger.fatal("(" + emps.getIdnumber() + "):" + e.getLocalizedMessage(), e);
            } else {
                logger.fatal(e.getLocalizedMessage(), e);

            }
            e.printStackTrace();
            addActionError(e.getLocalizedMessage());
            return ERROR;
        }
    }

    private boolean queryPrivilege(int moduleid, char privilege) {
        DetachedCriteria criteria = DetachedCriteria.forClass(UsertypeModule.class);
        criteria.createCriteria("usertypes", "ut").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.createCriteria("modules", "m").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.add(Restrictions.eq("m.moduleid", moduleid));
        criteria.add(Restrictions.eq("ut.usertypeid", ut.getUsertypeid()));
        UsertypeModule um = umodDao.getPrivilege(criteria);
        logger.info(um.getModulename());
        boolean p = false;
        switch (privilege) {
            case 'v': p = um.isViewable();
                break;
            case 'e': p = um.isEditable();
                break;
            case 'c': p = um.isCreateable();
                break;
            case 'd': p = um.isDeleteable();
                break;
        }
        return p;
    }

//getters and setters

这是我的数据访问对象中的代码: 'umodDao':

@SuppressWarnings("unchecked")
    public UsertypeModule getPrivilege(DetachedCriteria dc){
        Criteria criteria = dc.getExecutableCriteria(session);
        criteria.setMaxResults(1);
        return (UsertypeModule) criteria.uniqueResult();
    }

当我运行我的项目并导航到 dccr.jsp 我收到此错误:

May 31, 2011 8:34:52 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.StackOverflowError
    at java.util.HashMap.get(HashMap.java:300)
    at java.lang.Package.getSystemPackage(Package.java:491)
    at java.lang.Package.getPackage(Package.java:313)
    at java.lang.Class.getPackage(Class.java:698)
    at com.googlecode.s2hibernate.struts2.plugin.interceptors.SessionTransactionInjectorInterceptor.isCandidadeClass(SessionTransactionInjectorInterceptor.java:313)
    at com.googlecode.s2hibernate.struts2.plugin.interceptors.SessionTransactionInjectorInterceptor.injectHibernateCoreSession(SessionTransactionInjectorInterceptor.java:340)
    at com.googlecode.s2hibernate.struts2.plugin.interceptors.SessionTransactionInjectorInterceptor.injectHibernateCoreSession(SessionTransactionInjectorInterceptor.java:361)

是的,我使用 FHP(完整 Hibernate 插件 1.4GA),我的 Servlet 容器是 netbeans 7.0 上的 Tomcat 7.0。我已经挣扎了好几天,但每次尝试都失败了,堆栈跟踪指向 FHP 插件的 SessionTransactionInjectorInterceptor.injectHibernateCoreSession 方法。请帮助我,或者只是说一些可能有所启发的事情。


我怀疑这个问题与我的 tomcat 策略有关,因为当我升级到 fhp 2.2GA 时,我仍然遇到 stackoverflowerror 但是

java.security.AccessController.doPrivileged(Native Method)

是已经包含在堆栈跟踪中。但这只是一种怀疑。由于这个问题,我无法继续我的工作,因此我正在考虑将我的项目恢复到最新的工作修订版,以便继续我的工作,并最终在我能够解决这个持续存在的问题时提交我的更改。

I have dccr.jsp file that calls an action via the tag:

<s:action name="query-privilege" executeResult="false" var="privilege">
            <s:param name="moduleid">9</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">dccr</s:param>
</s:action>

i use this action to query module privileges amongst users, like this:

<s:if test="%{#privilege.allowable == false}">
       //do something
</s:if>

Here's my Action Support Class:

    private String pagename;
    private String moduleid;
    private boolean allowable;
    private String privilege;
    private final UsertypeModuleDAO umodDao = (UsertypeModuleDAO) ServletActionContext.getServletContext().getAttribute("usermoduleDAO");

    //loggers, session properties etc.

@Action(value = "/query-privilege", results = {
        @Result(name = "SUCCESSdccr", location = "/dccr.jsp"),
        @Result(name = "ERROR", location = "../error/messages.jsp")
    })
    @Override
    public String execute() {
        try {
            char p = privilege.charAt(0);
            int i = Integer.parseInt(moduleid);
            allowable = queryPrivilege(i, p);
            logger.info(privilege+", "+moduleid+", "+ut.getUsertypeid()+", "+allowable);
            return SUCCESS + pagename;
        } catch (Exception e) {
            if (emps != null) {
                logger.fatal("(" + emps.getIdnumber() + "):" + e.getLocalizedMessage(), e);
            } else {
                logger.fatal(e.getLocalizedMessage(), e);

            }
            e.printStackTrace();
            addActionError(e.getLocalizedMessage());
            return ERROR;
        }
    }

    private boolean queryPrivilege(int moduleid, char privilege) {
        DetachedCriteria criteria = DetachedCriteria.forClass(UsertypeModule.class);
        criteria.createCriteria("usertypes", "ut").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.createCriteria("modules", "m").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        criteria.add(Restrictions.eq("m.moduleid", moduleid));
        criteria.add(Restrictions.eq("ut.usertypeid", ut.getUsertypeid()));
        UsertypeModule um = umodDao.getPrivilege(criteria);
        logger.info(um.getModulename());
        boolean p = false;
        switch (privilege) {
            case 'v': p = um.isViewable();
                break;
            case 'e': p = um.isEditable();
                break;
            case 'c': p = um.isCreateable();
                break;
            case 'd': p = um.isDeleteable();
                break;
        }
        return p;
    }

//getters and setters

And here's my code in my Data Access Object: 'umodDao':

@SuppressWarnings("unchecked")
    public UsertypeModule getPrivilege(DetachedCriteria dc){
        Criteria criteria = dc.getExecutableCriteria(session);
        criteria.setMaxResults(1);
        return (UsertypeModule) criteria.uniqueResult();
    }

When i run my project and navigate to dccr.jsp I get this error:

May 31, 2011 8:34:52 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.StackOverflowError
    at java.util.HashMap.get(HashMap.java:300)
    at java.lang.Package.getSystemPackage(Package.java:491)
    at java.lang.Package.getPackage(Package.java:313)
    at java.lang.Class.getPackage(Class.java:698)
    at com.googlecode.s2hibernate.struts2.plugin.interceptors.SessionTransactionInjectorInterceptor.isCandidadeClass(SessionTransactionInjectorInterceptor.java:313)
    at com.googlecode.s2hibernate.struts2.plugin.interceptors.SessionTransactionInjectorInterceptor.injectHibernateCoreSession(SessionTransactionInjectorInterceptor.java:340)
    at com.googlecode.s2hibernate.struts2.plugin.interceptors.SessionTransactionInjectorInterceptor.injectHibernateCoreSession(SessionTransactionInjectorInterceptor.java:361)

Yeah, Im using FHP(Full Hibernate Plugin 1.4GA) and my Servlet Container is Tomcat 7.0 on netbeans 7.0. I've been stuggling for days but kept failing at each attempt, The stacktraces point to FHP Plugin's SessionTransactionInjectorInterceptor.injectHibernateCoreSession method. Please help me or just say anything that may shed some light.


I have a suspicion that this problem had to do something with my tomcat policy, because when i upgraded to fhp 2.2GA I still came across with stackoverflowerror however

java.security.AccessController.doPrivileged(Native Method)

is already included in the stacktrace. But this is only a suspicion. I cannot continue my work because of this problem so I am thinking of reverting my project's to the most recent working revision in order to continue my work and eventually commit my changes when I am able to fix this persistent problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

两相知 2024-11-17 10:17:07

java.lang.StackOverflowError 通常表示没有停止条件的递归调用。我会开始寻找一个。

java.lang.StackOverflowError usually means a recursive call that has no stopping condition. I'd start looking for one.

李白 2024-11-17 10:17:07

我刚刚检查了 SessionTransactionInjectorInterceptor 的代码。

使用 Class.getPackage() 部分地导致了该问题。他们不应该使用 getPackage() 而是从类名中解析出包名。

我不确定你如何解决这个问题。在遇到问题之前(即在 static{} 块中的某个位置)从同一个包加载类并调用 getPackage() 应该会有所帮助。

总的来说,struts2 不应该使用 getPackage,因为它有不同的用途。 (最重要的是,没有性能优势,但需要在全局锁上同步)。

I've just checked the code of SessionTransactionInjectorInterceptor.

The use of Class.getPackage() partly causes the problem. They should not use getPackage() but parse the package name out of the class name.

I'm not sure how you can play around the issue. Loading a class from the same package Before running into the problem (i.e. somewhere in a static{} block) and calling getPackage() should help.

Overall struts2 should not use getPackage since it's intended for different purposes. (on top of that there are no performance benefits but needs to synchronize on a global lock).

不再让梦枯萎 2024-11-17 10:17:07

我遇到了和你类似的问题,但不知何故,问题神奇地自行解决了。每当我运行它时,我都会得到这两个令人难以置信的长堆栈跟踪,它们是 StackOverflowException 的结果。

我听从了第一个回答者的建议,并在调试模式下运行它,看看是否存在一些永无休止的递归调用。然而,在调试模式下,问题不再出现。

我的理论是,这个堆栈溢出问题在某种程度上与 Struts2 FilterDispatcher 类有关。

如果您在代码中找不到任何问题,那么您也可能遇到这种情况。特别是,如果您的 Struts2 项目更像是一个只有很少代码的试验,并且您知道您没有在代码中的任何地方使用递归。

I had a similar problem to yours, but somehow the problem magically fixed itself. Whenever I ran it, I got this incredibly long couple of stack traces which were the result of a StackOverflowException.

I followed the advice of the first answerer and ran it in debug mode to see if there was some never-ending recursive call. However, during debug mode the problem didn't present itself anymore.

My theory is that this stack overflow problem was somehow related to the Struts2 FilterDispatcher class.

If you can't find anything wrong with your code, that could be what's happening to you as well. Especially, if your Struts2 project is more like a trial experiment for you with very little code and you know for a fact that you didn't use recursion anywhere in your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文