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

在JSP文件/page.jsp中尝试使用/WEB-INF/classes/Helper.class时遇到问题。JSP 2.0规范不允许引用未命名包(default package)中的类。为了解决这个问题,你需要将Helper类移动到一个命名包内。由于从JDK 1.4开始,导入未命名包的类是不合法的,这样做是为了保持向后兼容性。因此,必须避免依赖未命名包,确保所有引用的类都在指定的包内。
摘要由CSDN通过智能技术生成

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.

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.

解决方案

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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值