java.lang.ClassNotFoundException:org.apache.catalina.connector.Response

发布于 2024-10-20 08:35:19 字数 530 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

铜锣湾横着走 2024-10-27 08:35:19

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.

情绪少女 2024-10-27 08:35:19

显然,Tomcat 设计者认为 Web 应用程序获取其内部类不是一个好主意。以下是几个可能的原因:

  • 它使您的代码依赖于 Tomcat。
  • 当内部细节发生变化时,它会使你的代码变得脆弱;即这取决于 Tomcat 版本。
  • Tomcat 堆栈或 web 应用程序上下文中的其他内容可能会执行一些操作,这意味着您的 Response 对象是一个包装器而不是您期望的类。

为了让你的代码“工作”,你可能需要修改 Tomcat JAR 文件......这将使它更难以移植。有关可能帮助您割断自己喉咙的更多信息,请参阅此处。请注意,这是 Tomcat 5.5 特有的...与 Tomcat 6.0 版本的页面有所不同。


我想将其转换为 org.apache.catalina.connector.Response 的原因是在将 HTTP 响应标头发送到客户端之前读取它们。

我懂了。好吧,也许您应该实现一个自定义 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:

  • It makes your code dependent on Tomcat.
  • It makes your code fragile in the face of changes to internal details; i.e. it depends on the Tomcat version.
  • The Tomcat stack or other things inside your webapp context could do things that mean that your Response object is a wrapper rather than the class you are expecting.

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.


The reason I want to turn it to a org.apache.catalina.connector.Response is to read what's in the HTTP response headers before they are sent to the client.

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.

雨轻弹 2024-10-27 08:35:19

我认为你不能使用那个类。我不确定你想做什么,但是使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文