Я должен закрыть сервлет outputstream? [дубликат]

Обходное решение должно установить http://apserver.sourceforge.net на Вашей локальной машине, настроить ее и выполнить драгоценные камни через этот прокси.

  • Установка: Просто загрузите apserver 097 (а не экспериментальные 098!) и распаковывают.
  • Настройте: Отредактируйте server.cfg файл и поместите значения для Вашего прокси MS в PARENT_PROXY и PARENT_PROXY_PORT. Введите значения для ДОМЕНА и ПОЛЬЗОВАТЕЛЯ. Оставьте незаполненный ПАРОЛЬ (ничто после двоеточия) †“, Вам предложат при запуске его.
  • Выполнение apserver: cd aps097; python main.py
  • Драгоценные камни Выполнения: gem install—http-proxy http://localhost:5865/ library

57
задан Community 23 May 2017 в 12:10
поделиться

2 ответа

You indeed don't need to do so.

Thumb rule: if you didn't create/open it yourself using new SomeOutputStream(), then you don't need to close it yourself. If it was for example a new FileOutputStream("c:/foo.txt"), then you obviously need to close it yourself.

Reasons that some people still do it are just to ensure that nothing more will be written to the response body. If it would ever happen, then this will cause an IllegalStateException in the appserver logs, but this wouldn't affect the client, so the client still gets the proper response. This is also an easier debug to spot the potential problems in the request-response chain which you wouldn't see at first glance. For example, something else is appending more data to the response body somewhere further down in the chain.

Another reason which you see among starters is that they just wanted to prevent that more data is written to the response body. You see this often when JSP incorrectly plays a role in the response. They just ignore the IllegalStateExceptions in the logs. Needless to say that this particular purpose is bad.

68
ответ дан 24 November 2019 в 19:43
поделиться

No you don't need to close it. If you do you basically end the response to the client. After closing the stream you cannot send anything else to the client until the next request. You didn't open the stream, so you don't have to close it.

9
ответ дан 24 November 2019 в 19:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: