Java 从EL调用方法。为什么';这不管用吗?
我怎样才能让它工作呢Java 从EL调用方法。为什么';这不管用吗?,java,jsp,el,Java,Jsp,El,我怎样才能让它工作呢 <% class thing { public String doit () { return "doing it"; } } request.setAttribute ("thing", new thing ()); %> <body> ${requestScope.thing.doit ()} </body> ${request
<%
class thing {
public String doit () {
return "doing it";
}
}
request.setAttribute ("thing", new thing ());
%>
<body>
${requestScope.thing.doit ()}
</body>
${requestScope.thing.doit()}
我没有创建单独编译类的自由。它必须是内联的
谢谢。您不需要修改请求,因为scriptlet是服务器端的,更好地使用它
<%
public String doit () {
return "doing it";
}
%>
<body>
<%
doSomething();
%>
</body>
有了这个,你可以调用你的函数。但最终,使用Scriptlet是一种非常糟糕的做法。很难调试。难读,等等。在SO中读很多好的答案。如果你使用getter符号,那么你可以说
东西。doit
。谢谢,但这不是我问题的答案。我没有要求另一种方法(我知道,我也知道使用Scriptlet的“坏习惯”,但这并不是我真正要做的决定)。