在 Tomcat 5.5 上将 JSP 页面语法设置为 JDK 1.5
我在 Tomcat 文档中读到,可以使用 JSP 页面发送到 Tomcat 服务器,用什么 JDK 来编译它,问题是如何?
我想要这样做的原因是我正在开发一个页面来集成到正在运行的Web应用程序中,所以我不想更改默认的Tomcat jdk设置,但是默认的JDK 1.4不支持List语法,就像JDK 1.5一样,如果不使用旧的 JDK 语法进行重新开发,我就无法放弃它......
如果我的假设完全错误,请纠正我......
如果不可能动态向 Tomcat 发送 JDK 版本,我如何更改默认的 JDK ,我知道它在 $CATALINA_BASE/conf/web.xml 中,但我不知道需要更改什么...
谢谢前面。
I have read in the Tomcat doc that its possiable to send to the Tomcat server with a JSP page what JDK to compile it with, the question is how?
The reason why i want to do it is that i am developing a page to integrate into running web application so I prefer not to change the defult Tomcat jdk setting, BUT the JDK 1.4 wich is the default isnt supporting the List syntax as JDK 1.5, and i cannot drop that without doing redeveloping in old JDK syntax.....
Please correct me if im tottaly wrong with my assumptions....
If it isnt possiable to dynamicly send the Tomcat the JDK version how can i change the default JDK, I know its in $CATALINA_BASE/conf/web.xml but i dont know what need to be changed...
Thanks Upfront.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Jasper 文档,默认的源和目标级别为JSP 编译由 Tomcat 使用的 JDK 决定,并且可以使用 init 参数覆盖(如上页所述)。
但我不认为这会对你有帮助。
据我所知,您的 Tomcat 的 JVM 是 1.4.x,但您希望使用 1.5 类库在源代码级别 1.5 上进行编译。我相信这是不可能的。
JDK 1.4 中的 Java 编译器无法编译 Java 1.5 语法。此外,JDK 1.4 中的类库是(...等等...)Java 1.4,而不是 1.5,因此如果您的 JSP 使用 1.5 类或方法,则生成的 Java 将无法编译。即使您确实成功编译了 JSP/生成的 Java(例如使用另一个 JVM),您也很可能会看到在 JDK 1.4.x 上加载代码时出现运行时问题。
AFAIK,如果您想在 JSP 中使用 Java 1.5 功能,您别无选择,只能使用 JDK 1.5 或更高版本作为 Tomcat 的 JVM。
坦率地说,您应该尽快升级到 JDK 1.6。 JDK 1.4.x 已经停产,Java 1.5 的 EOL 也不远了。此外,自 1.4.2 以来,还添加了无数的性能调整、错误修复和新功能。
According to the Jasper documentation, the default source and target level for JSP compilation is determined by the JDK that Tomcat is using, and can be overriden using init parameters (described in the above page).
But I don't think this is going to help you.
From what I can make out, your Tomcat's JVM is 1.4.x, but you want to compile at source level 1.5 with the 1.5 class libraries. I believe that this cannot possibly work.
The Java compiler in JDK 1.4 is not capable of compiling Java 1.5 syntax. Furthermore, the class libraries in JDK 1.4 are (... wait for it ...) Java 1.4, not 1.5, so if your JSPs uses 1.5 classes or methods the generated Java would not compile. And even if you did manage to compile the JSPs / generated Java (e.g. with another JVM), you'd most likely see runtime problems loading the code on JDK 1.4.x.
AFAIK, if you want to use Java 1.5 features in your JSPs, you've no choice but to JDK 1.5 or later as your Tomcat's JVM.
And frankly, you should be upgrading to JDK 1.6 ASAP. JDK 1.4.x has been End-of-Lifed, and EOL for Java 1.5 can't be that far off. Besides, zillions of performance tweaks, bug fixes and new features have been added since 1.4.2.
Tomcat只是一个java应用程序。它是在JVM下运行的。因此,使用的 JVM 版本并不取决于 Tomcat,而是取决于计算机上安装的 java 和定义的 JAVA_HOME 环境变量。
因此,请执行以下操作。
首先检查您的计算机上安装了哪些 JDK 和 JRE。如果您没有特殊原因需要进行多个 java 安装,请删除除最后一个之外的所有内容。
其次,检查您的 JAVA_HOME 环境。多变的。它应该指向“正确的”java 安装。
现在运行您的 tomcat 并享受 java 1.6 功能,包括泛型、枚举和您想要的其他功能。
顺便说一句,你为什么使用 Tomcat 5.5?至少迁移到 tomcat 6,或者更好的 Tomcat 7,它具有很酷的新功能。
Tomcat is just a java application. It is running under JVM. So, the JVM version is used does not depend on Tomcat but on java installed on your machine and JAVA_HOME environment variable defined.
So, do the following.
First check which JDKs and JREs are installed on your machine. If you do not have special reasons to hold multiple java installation remove everything except the last one.
second, check your JAVA_HOME env. variable. It should point to the "correct" java installation.
Now run your tomcat and enjoy java 1.6 features including generics, enum and what else you want.
BTW, why are you using Tomcat 5.5? Move to at least tomcat 6, or, better Tomcat 7 that has cool new features.