Java:如何调试无效的 JSTL 声明?
我在 SO(以及整个网络)上见过这种问题很多次。例如:
今天早些时候,我尝试使用 JSP(常规 .jsp,而不是 .jspx) )这样做,因为我愚蠢地剪切/粘贴了在网上找到的一些示例:
<%@ taglib prefix = "c" uri = "http://java.sun.com/jstl/core"%>
然后我的 .jsp 给出了一个空白页面。 Tomcat 日志中没有错误消息。没有什么。只是一张空白页。
当然,(我在这里是在讽刺),正确的行是这样的:
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
缺少“jsp/”(我在另一个 SO 问题中找到了提示)。
显然此类问题很常见。
我不敢相信你必须等待事情“不起作用”才能知道你有一个错误,老实说我对网上找到的问题数量(以及这里的答案)感到有点困惑基本上是“修正你的声明”。
我的问题很简单:你怎么知道这是一个声明问题?诊断和解决此类问题需要什么思维过程?有没有可以提供帮助的工具? (我不知道,比如说,nxml 模式下的 IntelliJ IDEA 或 Eclipse 或 Emacs 会实时警告您声明的 URI 无效吗?)
I've seen this kind of issue on SO (and on the Net overall) quite a few times. For example here:
JSPX namespaces not visible for EL functions?
Earlier today I was trying on a JSP (regular .jsp, not .jspx) to do this, because I stupidly cut/pasted some example found on the net:
<%@ taglib prefix = "c" uri = "http://java.sun.com/jstl/core"%>
Then my .jsp was giving a blank page. No error message in the Tomcat log. No nothing. Just a blank page.
While, of course (I'm being sarcastic here), the correct line was this:
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
There was a "jsp/" missing (which I found a hint to in yet another SO question).
So obviously such issues are common.
I can't believe you have to wait for things "not to work" to know you've there's an error and I'm honestly a bit confuzzabled by the number of questions found on the net (and here on SO) where the answer is basically "fix your declaration".
My question here is simple: how do you know that it's a declaration issue? What thought process is required here to diagnose and troubleshoot such issues? Are there tools that can help here? (I don't know, like, say, IntelliJ IDEA or Eclipse or Emacs in nxml-mode warning you in real time that the declared URI is invalid?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在网络浏览器中查看页面源代码,如果您看到标签未解析,则说明未找到/加载标签库。
我不确定我是否理解您的最后一条语句,但是如果在类路径中找不到 taglib,Eclipse 会出现错误并显示红线。
View page source in webbrowser, if you see the tags unparsed, then the taglib is not found/loaded.
I am not sure if I understand your last statement, but Eclipse errors here with a red line if the taglib is not found in classpath.
http://java.sun.com/jstl/core
是一个有效的 JSTL 声明 - 它是 JSTL 核心 1.0。http://java.sun.com/jsp/jstl/core
是 JSTL 核心 1.1。http://java.sun.com/jstl/core
is a valid JSTL declaration - it is the URI for JSTL core 1.0.http://java.sun.com/jsp/jstl/core
is the URI for JSTL core 1.1.