如何确定 IDEA 中 JSTL 表达式变量(pageContext 属性)的来源?
我们有一个应用程序大量使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
${myObject}
基本上解析为jspContext.findAttribute("myObject")
分别在页面、请求、会话和应用程序范围中搜索属性并返回它找到的第一个非null
值。你可以让 IDE 变得多么智能,它无法事先(在构建/编译期间)知道它被设置在哪个范围内。有太多的因素(可见的和不可见的)需要考虑。找到这个问题的唯一可靠方法是通过在运行时显式访问所需的范围以编程方式进行:
上面的示例应该为实际设置的范围之一返回
true
。The
${myObject}
basically resolves tojspContext.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:
The above example should return
true
for one of the scopes where it is actually been set.