简体   繁体   中英

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. 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.

response.setStatus(HttpServletResponse.SC_NOT_FOUND);

I even tried to do a

 response.flushBuffer();

to commit the setStatus, but with no luck.

What am I missing? According to the TomCat 6.0 docs the setStatus() works just the same as in version 7 .

Obviously one solution is to upgrade the clients TomCat server, but we want to avoid that.

-Thank you.

I usually use HttpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); You may want to give this a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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