如何从JSP页面引用java .class文件? [英] how to reference a java .class file from a JSP page?

查看:192
本文介绍了如何从JSP页面引用java .class文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在app目录的根目录中有JSP文件(/page.jsp)。我想使用位于/WEB-INF/classes/Helper.class中的这个类。

I have the JSP file (/page.jsp) in the root of my app directory. I want to use this class located in /WEB-INF/classes/Helper.class.

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

I tried using the JSP page import statment with the class name but that didn't work. How can I reference Helper.class so that I can use it my JSP? I don't want to include the class in a package/JAR.

推荐答案

好的,直到我才知道这个抬头看了看。 JSP Spec(JSP.11.2 JSP页面实现类)是你的朋友。您需要从默认包中移动该类。

Okay, I didn't know this until I looked it up. The JSP Spec (JSP.11.2 JSP Page Implementation Class) is your friend. You'll need to move that class from the default package.


从JSP 2.0开始,将
引用到未命名的
(即默认值)中的任何类是违法的包。这可能是
导致某些
容器的转换错误,特别是那些
在JDK 1.4或更高
环境中运行的容器。不幸的是,但是b $ b不可避免地会破坏
与一些较旧的JSP
应用程序的兼容性。但是,从JDK 1.4开始,
从未命名的
包中导入类是无效的(参见
http://java.sun.com/j2se/1.4/compatibility.html#source
了解详情)。因此,对于转发
的兼容性,应用程序必须不依赖于未命名的包
。这个
限制也适用于引用类的所有其他
情况,
,例如为TLD中的标记指定类名

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 http://java.sun.com/j2se/1.4/compatibility.html#source 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

这篇关于如何从JSP页面引用java .class文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆