Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获取和修剪jspwriter(out)缓冲区的内容_Java_Jsp_Buffer_Trim_Bufferedwriter - Fatal编程技术网

Java 如何获取和修剪jspwriter(out)缓冲区的内容

Java 如何获取和修剪jspwriter(out)缓冲区的内容,java,jsp,buffer,trim,bufferedwriter,Java,Jsp,Buffer,Trim,Bufferedwriter,在JSP页面上,JSPService以out的形式公开JSPWriter类,如inout.println(“foobar”)我想做的是将输出缓冲区的内容存储到一个字符串变量,然后trim所述变量。问题是我不太确定要捕获out缓冲区的内容 我试图找出一种直接修剪缓冲区的方法,但我找不到这样的方法。因此,我认为可能的工作方式是将缓冲区的内容输出到字符串变量,修剪变量本身,清除out缓冲区,然后将变量写入out缓冲区: // Returns the object, not the contents o

JSP
页面上,
JSPService
out
的形式公开
JSPWriter类,如in
out.println(“foobar”)
我想做的是将
输出缓冲区的内容存储到一个字符串变量,然后
trim
所述变量。问题是我不太确定要捕获out缓冲区的内容

我试图找出一种直接修剪缓冲区的方法,但我找不到这样的方法。因此,我认为可能的工作方式是将缓冲区的内容输出到字符串变量,修剪变量本身,清除out缓冲区,然后将变量写入out缓冲区:

// Returns the object, not the contents of the buffer
// Need the contents for the rest of the code to work
String outBufferContents = out.toString();

// Trim out buffer contents
outBufferContents = outBufferContents.trim();

// Clear out buffer
out.clearBuffer();

// Write trimmed buffer contents to out buffer
out.print(outBufferContents);
您对我如何获取输出缓冲区的内容,甚至直接修剪输出缓冲区有什么建议吗


非常感谢您提供的任何帮助。

为什么您不能在将字符串放入缓冲区之前修剪它?如果你做不到这一点,那么你可以尝试对回答进行过滤。这是一个好问题。因为响应正在写入一个独立的web服务器,这不在我的控制范围内,我更愿意在刷新和发送输出缓冲区之前修剪内容,而不是让启动请求的web服务器执行字符串操作。上面的代码在我控制的web服务器上。我相信对响应的筛选会起作用。谢谢你。