假设这是按照 servlet 规范作为网络服务器运行的,您可以使用过滤器。
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
@WebFilter(asyncSupported = true, filterName = "LegacyAppender", urlPatterns = { "/paths/tofile" })
public class AppendFilter implements Filter {
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
chain.doFilter(req, resp);
HttpServletResponse hsr = (HttpServletResponse) resp;
hsr.getWriter().print("\r\n");
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}