如何确定 IDEA 中 JSTL 表达式变量(pageContext 属性)的来源?

发布于 2024-08-14 20:41:22 字数 427 浏览 2 评论 0原文

我们有一个应用程序大量使用 JSTL 表达式和自定义标记库,这意味着我们的 pageContext 属性几乎可以在任何地方设置。我该如何确定它们的起源?考虑一下这样的事情:

<c:out value="${ myObject['SOME_KEY'] }" />

我需要知道 myObject 来自哪里——它是如何进入 pageContext 的?我正在使用 IDEA,因此如果有一个在 IDE 中确定这一点的快捷方式,那将是最有帮助的。

编辑:

我不想知道范围,但实际上在哪个物理文件中设置了该属性。与 IDEA 右键单击​​上下文菜单中的“查找用法...”功能几乎相同。如果我将三个包含深入到可能使用标签库和模板的 JSP 中,则可以在 pageContext 中设置的属性几乎可以在任何地方设置。我想找到该属性的用法和实例。

We've got an app that makes heavy use of JSTL expressions and custom taglibs, which means our pageContext attributes could have been set just about anywhere. How do I go about determining where they originated? Consider something like:

<c:out value="${ myObject['SOME_KEY'] }" />

I need to know where myObject came from -- how did it make its way into the pageContext? I am using IDEA, so if there is a shortcut for determining that within the IDE, it would be most helpful.

EDIT:

I don't want to know about the scope, but in what physical file the attribute was actually set. Almost identical to the Find Usages... functionality in the right-click context menu of IDEA. If I'm three includes deep into a JSP that might be using taglibs and templating, an attribute set within the pageContext could have been set just about anywhere. I would like to find usages and instances of that attribute.

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

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

发布评论

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

评论(1

阳光的暖冬 2024-08-21 20:41:22

${myObject} 基本上解析为 jspContext.findAttribute("myObject") 分别在页面、请求、会话和应用程序范围中搜索属性并返回它找到的第一个非null值。

你可以让 IDE 变得多么智能,它无法事先(在构建/编译期间)知道它被设置在哪个范围内。有太多的因素(可见的和不可见的)需要考虑。找到这个问题的唯一可靠方法是通过在运行时显式访问所需的范围以编程方式进行:

"myObject" is in:
<br>Page scope? ${not empty pageScope.myObject}
<br>Request scope? ${not empty requestScope.myObject}
<br>Session scope? ${not empty sessionScope.myObject}
<br>Application scope? ${not empty applicationScope.myObject}

上面的示例应该为实际设置的范围之一返回 true

The ${myObject} basically resolves to jspContext.findAttribute("myObject") which searches for the attribute in respectively the page, request, session and application scopes and returns the first non-null value it finds.

How smart you can make an IDE, it cannot know beforehand (during build/compile) in which scope it is been set. There are too much factors (visible as well as invisible) which needs to be taken into consideration. The only reliable way to find this out is doing it programmatically by accessing the desired scopes explicitly during runtime:

"myObject" is in:
<br>Page scope? ${not empty pageScope.myObject}
<br>Request scope? ${not empty requestScope.myObject}
<br>Session scope? ${not empty sessionScope.myObject}
<br>Application scope? ${not empty applicationScope.myObject}

The above example should return true for one of the scopes where it is actually been set.

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