java - 从 EL 调用方法。为什么这不起作用?
问题描述
我怎样才能让它发挥作用?
<%
class thing {
public String doit () {
return "doing it";
}
}
request.setAttribute ("thing", new thing ());
%>
<body>
${requestScope.thing.doit ()}
</body>
我没有创建单独编译类的自由。它必须是内联的。
谢谢。
解决方案
您不需要请求,因为 scriptlet 是服务器端的,更好的用途是
<%
public String doit () {
return "doing it";
}
%>
<body>
<%
doSomething();
%>
</body>
用这个你调用你的函数。但归根结底,使用小脚本是一个非常糟糕的做法。很难调试。难以阅读,等等等等。在 SO 中阅读了很多很好的答案喜欢这个
推荐阅读
- crystal-reports - 如果一条或多条记录包含特定数据,则在 Crystal Report 中显示对象
- ios - Alamofire 传递参数具有以下类型
- python - 如何在 Python 中批量运行一个大文件
- dji-sdk - DJI Windows SDK:将 Mavic 2 Pro 录制的视频保存到 SD 卡的 API 程序是什么
- json - 颠簸变换后json对象的排序
- python - 如何将 Python 对象转换为 Cython 扩展类型的 std::vector 并返回?
- postgresql - Postgres 在 funcio 中调用 Function 不是我所期望的
- python - 在 python 中向下舍入(0.10 的倍数)
- android-recyclerview - Android androidx.recyclerview 移除滚动效果
- cloud - 我在哪里可以在线获得免费的 AiX 虚拟机?