java.lang.ClassNotFoundException:org.apache.catalina.connector.Response
我正在使用 Eclipse Helios 对在 Tomcat 5.5 上运行的 JSP 和 POJO 进行编程。我尝试使用 org.apache.catalina.connector.Response 类,如下所示:
import org.apache.catalina.connector.*; ... 响应 resp = (响应) r;
其中 r 是 HttpServletResponse 的实例。 Eclipse 没有给出任何警告,并且该项目编译良好。但是,当我浏览到包含此代码的页面时,出现以下错误:
java.lang.ClassNotFoundException: org.apache.catalina.connector.Response
知道出了什么问题吗?
我也按照这个方法尝试过,结果是一样的。
org.apache.catalina.connector.Response resp = (org.apache.catalina.connector.Response) r;
谢谢,
伊恩
I am using Eclipse Helios to program JSP and POJOs running on Tomcat 5.5. I am trying to use the org.apache.catalina.connector.Response class as follows:
import org.apache.catalina.connector.*;
...
Response resp = (Response) r;
where r is an instance of HttpServletResponse. Eclipse gives no warnings, and the project compiles fine. However, when I browse to a page that contains this code, I get the following error:
java.lang.ClassNotFoundException: org.apache.catalina.connector.Response
any idea of what is going wrong?
I have also tried it this way, with the same result.
org.apache.catalina.connector.Response resp = (org.apache.catalina.connector.Response) r;
Thanks,
Ean
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ClassNotFoundException 意味着类在编译时可用,但在运行时不可用。因此,如何将其导入源代码中并没有什么区别。
我没有检查过,但 Tomcat 很可能不允许 Web 应用程序访问其内部类。我没有检查的原因是我知道即使我能做到,这也是一个坏主意。您应该针对 API(在本例中为 javax.servlet.* 下的内容)编写代码,而不是针对实现编写代码。
A ClassNotFoundException means that a class was available at compile time, but not at run time. So it makes no difference how you import it in your source code.
I haven't checked, but it's quite possible that Tomcat doesn't let web apps access its internal classes. And the reason I haven't checked is that I know it'd be a bad idea even if I could do it. You should code to the API (in this case, the stuff under javax.servlet.*) not to the implementation.
显然,Tomcat 设计者认为 Web 应用程序获取其内部类不是一个好主意。以下是几个可能的原因:
为了让你的代码“工作”,你可能需要修改 Tomcat JAR 文件......这将使它更难以移植。有关可能帮助您割断自己喉咙的更多信息,请参阅此处。请注意,这是 Tomcat 5.5 特有的...与 Tomcat 6.0 版本的页面有所不同。
我懂了。好吧,也许您应该实现一个自定义 Valve。 (这是 Tomcat 特定的事情。)或者更好的是,查看 现有的 Valve 实现 将为您完成这项工作。
Clearly, the Tomcat designers don't think that it is a good idea for webapps get at its internal classes. Here's a couple of possible reasons:
To change make your code "work" you would probably need to tinker with the Tomcat JAR files ... which will make it even less portable. For more information that might help you to slit your own throat, refer here. Note that this is Tomcat 5.5 specific ... and the Tomcat 6.0 version of the page is different.
I see. Well perhaps you should be implementing a custom Valve. (This is a Tomcat-specific thing.) Or better still, see if one of the existing Valve implementations will do the job for you.
我认为你不能使用那个类。我不确定你想做什么,但是使用 HttpServletResponse 就可以了。
I don't' think you can use that class. I am not sure what you are trying to do, but use HttpServletResponse and you should be good to go.