当前位置 : 主页 > 编程语言 > java >

如何从JSP页面引用java .class文件?

来源:互联网 收集:自由互联 发布时间:2021-06-25
我在我的app目录的根目录中有JSP文件(/page.jsp).我想使用位于/WEB-INF/classes/Helper.class中的这个类. 我尝试使用带有类名的JSP页面导入语句,但这不起作用.我如何引用Helper.class以便我可以将它
我在我的app目录的根目录中有JSP文件(/page.jsp).我想使用位于/WEB-INF/classes/Helper.class中的这个类.

我尝试使用带有类名的JSP页面导入语句,但这不起作用.我如何引用Helper.class以便我可以将它用于我的JSP?我不想在class / JAR中包含该类.

好吧,直到我查了一下,我才知道这一点. JSP Spec (JSP.11.2 JSP Page Implementation Class)是你的朋友.您需要从默认包中移动该类.

As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a. default) package. This may result in a translation error on some containers, specifically those that run in a JDK 1.4 or greater environment. It is unfortunate, but unavoidable, that this will break compatibility with some older JSP applications. However, as of JDK 1.4, importing classes from the unnamed package is not valid (see 07001 for details). Therefore, for forwards compatibility, applications must not rely on the unnamed package. This restriction also applies for all other cases where classes are referenced, such as when specifying the class name for a tag in a TLD

网友评论