我有一个包含 823237 个字符的字符串。它实际上是一个 xml 文件,出于测试目的,我想作为响应形式返回一个 servlet。
我已经尝试了我能想到的一切
1)用整个字符串创建一个常量......在这种情况下Eclipse抱怨(在servlet类名下有一条红线) -
 The type generates a string that requires more than 65535 bytes to encode in Utf8 format in the constant pool
2) 将整个字符串分成 20 个字符串常量并直接写入out对象,例如:
out.println( CONSTANT_STRING_PART_1 + CONSTANT_STRING_PART_2 + 
             CONSTANT_STRING_PART_3 + CONSTANT_STRING_PART_4 +
             CONSTANT_STRING_PART_5 + CONSTANT_STRING_PART_6 + 
     // add all the string constants till .... CONSTANT_STRING_PART_20); 
在这种情况下……构建失败……抱怨……
   [javac] D:\xx\xxx\xxx.java:87: constant string too long
   [javac]      CONSTANT_STRING_PART_19 + CONSTANT_STRING_PART_20); 
                                                    ^
3) 将 xml 文件作为字符串读取并写入out object.. 在这种情况下我得到
SEVERE: Allocate exception for servlet MyServlet
Caused by: org.apache.xmlbeans.XmlException: error: Content is not allowed in prolog.
servlet最后我的问题是......我怎样才能从???返回这么大的字符串(作为响应) ?