struts2数据切入字符串发送到jsp
我又遇到了这个问题...
所以我的 Struts2 应用程序中有字符串数据。这个数据相当大,从 html 读取 36KB 数据,代码如下:
BufferedReader reader = new BufferedReader(new FileReader("FILE.html"));
String readData;
while( (readData = reader.readLine()) != null) {
fileData.append(new String(readData.getBytes(),"UTF-8"));
}
reader.close();
fileData.trimToSize();
this.data2display = fileData.toString();
this.setData2display(this.data2display.replaceAll("\\s+", " "));
我在 jsp 文件中显示 data2display,只有:
<s:property value="data2display" escape="false" escapeJavaScript="false" />
Aaaaaand... 当我调试控制器时,该数据是完整的,但当我尝试在 jsp 中显示它时。我只有部分数据。我没有任何错误/调试日志。
知道如何检查/修复它吗?
我的应用程序:(struts2,jsp)一切都来自appfuse-basic-struts原型。
i've got this problem again...
So i've got String data in my Struts2 app. this data is quite big, 36KB data read from html with code:
BufferedReader reader = new BufferedReader(new FileReader("FILE.html"));
String readData;
while( (readData = reader.readLine()) != null) {
fileData.append(new String(readData.getBytes(),"UTF-8"));
}
reader.close();
fileData.trimToSize();
this.data2display = fileData.toString();
this.setData2display(this.data2display.replaceAll("\\s+", " "));
I display data2display in my jsp file, with just:
<s:property value="data2display" escape="false" escapeJavaScript="false" />
Aaaaaand... This data is entire while i'm debugging controller, but while i try to display this in jsp. I've got only part of data. I haven't got any error/debug logs.
Any idea how to check it/fix it ?
My app: (struts2, jsp) everything is from appfuse-basic-struts archetype.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我个人的起点是 PropertyTag 的来源,然后从那里开始遵循代码。
在本例中,从 PropertyTag< 开始/a>.您会看到它扩展了 ComponentTagSupport ,它又扩展了 StrutsBodyTagSupport。
这就是有趣的地方; toString 方法使用 FastByteArrayOutputStream 使用 8192 字节的默认块大小(缓冲区)。使用默认构造函数,如 完成StrutsBodyTagSupport 您无法输出包含更多数据的字符串。
由于不是 Struts 专家,我犹豫是否要说这是一个实现错误;恕我直言,它应该根据要打印的值计算缓冲区大小。不幸的是,事实并非如此。所以我认为没有一个简单的方法可以解决这个问题。
显然,不容易的方法是定义一个小于 8k 字节的字符串数据部分列表,并在 JSP 中迭代该列表,或者仅使用 c:out 或类似的东西。
这可能不是您正在寻找的答案,但我希望这至少能帮助您了解您所遇到的麻烦。
My personal start point would be the source of PropertyTag, and from there on follow the code.
In this case, start with PropertyTag. You see that it extends ComponentTagSupport, which in turn extends StrutsBodyTagSupport.
This is where it gets interesting; the
toString
method uses a FastByteArrayOutputStream which uses a default block size (buffer) of 8192 bytes. Using the default constructor, as done by StrutsBodyTagSupport you can't output a String with more data than that.Being not an expert on Struts I hesitate to say that's an implementation bug; it should IMHO compute the buffer size from the
value
to be printed. Unfortunately, it doesn't. So I don't think there's an easy way around it.The non-easy way is obviously defining a List of String data parts smaller than 8k bytes, and iterate over that list in the JSP, or just use c:out or something like that.
This may not be the answer you're looking for, but I hope this will at least help you understand the trouble you're in.