未捕获的异常:java.lang.ClassNotFoundException:
这是一个运行 Apache 和 Tomcat 的 Windows 服务器。我向现有包添加了一个新类,并尝试从 jsp 页面引用它,如下所示:
jsp:useBean id="promotion" class="MY.NEWCLASS" scope="session"
我是否缺少某些内容?我需要做一些特殊的事情来将类添加到包中吗?提前致谢。
jsp 页面加载正常,但是当我尝试单击使用此类的按钮时,我得到 未捕获的异常:java.lang.ClassNotFoundException:MY.NEWCLASS
this is a windows server running Apache and Tomcat. I added a new class to an existing package and tried to reference it from a jsp page like this:
jsp:useBean id="promotion" class="MY.NEWCLASS" scope="session"
am I missing something? Do I need to do something special to add a class to a package? Thanks in advance.
the jsp page loads fine, but when I try clicking on the button that uses this class I get
uncaught exception: java.lang.ClassNotFoundException:MY.NEWCLASS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要确保该类文件存在于已部署的 Web 应用程序的
/WEB-INF/classes/MY/NEWCLASS.class
中。或者,当它位于名为filename.jar
的 JAR 文件内的文件夹/MY/NEWCLASS.class
中时,您需要确保它存在于中已部署 Web 应用程序的 /WEB-INF/lib/filename.jar
。请注意,完全限定名称区分大小写。所以名称必须完全匹配。也许您对问题中的代码示例不小心,但以这种方式使用大写字母不是正常的 命名约定。例如,它实际上有可能被称为
my.NewClass
。然后您应该在jsp:useBean
中进行这样的声明。You need to ensure that the class file is present in
/WEB-INF/classes/MY/NEWCLASS.class
of the deployed webapplication. Or when it's in a folder/MY/NEWCLASS.class
inside a JAR file with the namefilename.jar
, then you need to ensure that it is present in/WEB-INF/lib/filename.jar
of the deployed webapplication.Please note that the fully qualified name is case sensitive. So the name must be an exact match. Maybe you was careless with the code example in your question, but using capitals this way is not a normal naming convention. Chances exist that it is actually called
my.NewClass
for example. You should then declare as such in yourjsp:useBean
.这看起来像是您忘记将新类部署到服务器。你如何调试这个?
首先,您可以检查类路径。在出现异常的地方,获取当前的类加载器:
如果是 URLClassLoader,询问它的 URL:
现在您可以检查输出是否包含您期望的内容。
This looks like you forget to deploy the new class to the server. How can you debug this?
First, you can examine the classpath. In the place where you get the exception, get the current classloader:
If that's a URLClassLoader, ask it for it's URLs:
Now you can check that the output contains what you expect.