首页 > 解决方案 > 从 EL 调用方法。为什么这不起作用?

问题描述

我怎样才能让它发挥作用?

<%

    class thing {

        public String doit () { 
            return "doing it";
        }

    }

    request.setAttribute ("thing", new thing ());

%>


<body>
    ${requestScope.thing.doit ()}
</body>

我没有创建单独编译类的自由。它必须是内联的。

谢谢。

标签: javajspel

解决方案


您不需要请求,因为 scriptlet 是服务器端的,更好的用途是

<%
        public String doit () { 
            return "doing it";
        }
%>


<body>
   <%
doSomething();
%>
</body>

用这个你调用你的函数。但归根结底,使用小脚本是一个非常糟糕的做法。很难调试。难以阅读,等等等等。在 SO 中阅读了很多很好的答案喜欢这个


推荐阅读