开发者

struts2 data cut in string send to jsp

开发者 https://www.devze.com 2023-01-13 21:40 出处:网络
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:

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" esca开发者_如何学JAVApe="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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号