简体   繁体   English

Java Servlet:TomCat 6不能设置HTTP状态代码

[英]Java servlets: Setting HTTP status code doesn't work with TomCat 6

I'm simply trying to set HTTP status code for the Http Servlet Response. 我只是尝试为Http Servlet响应设置HTTP状态代码。 And this works perfectly in development with TomCat 7. But on the customers server, which runs TomCat6 (6.0.36) the command is simply ignored. 这在使用TomCat 7的开发中非常有效。但是,在运行TomCat6(6.0.36)的客户服务器上,该命令将被忽略。

response.setStatus(HttpServletResponse.SC_NOT_FOUND);

I even tried to do a 我什至试图做一个

 response.flushBuffer();

to commit the setStatus, but with no luck. 提交setStatus,但没有运气。

What am I missing? 我想念什么? According to the TomCat 6.0 docs the setStatus() works just the same as in version 7 . 根据TomCat 6.0文档setStatus()的功能与版本7中的相同。

Obviously one solution is to upgrade the clients TomCat server, but we want to avoid that. 显然,一种解决方案是升级客户端TomCat服务器,但我们希望避免这种情况。

-Thank you. -谢谢。

I usually use HttpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); 我通常使用HttpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); You may want to give this a try. 您可能想尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM