Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8004653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:58:42+00:00 2026-06-04T16:58:42+00:00

I have a string that has 823237 characters in it. its actually an xml

  • 0

I have a string that has 823237 characters in it. its actually an xml file and for testing purpose I want to return as a response form a servlet.

I have tried everything I can possible think of

1) creating a constant with the whole string… in this case Eclipse complains (with a red line under servlet class name) –

 The type generates a string that requires more than 65535 bytes to encode in Utf8 format in the constant pool

2) breaking the whole string into 20 string constants and writing to the out object directly
something like :

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); 

in this case … the build fails .. complaining..

   [javac] D:\xx\xxx\xxx.java:87: constant string too long
   [javac]      CONSTANT_STRING_PART_19 + CONSTANT_STRING_PART_20); 
                                                    ^

3) reading the xml file as a string and writing to out object .. in this case I get

SEVERE: Allocate exception for servlet MyServlet
Caused by: org.apache.xmlbeans.XmlException: error: Content is not allowed in prolog.

Finally my question is … how can I return such a big string (as response) from the servlet ???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:58:43+00:00Added an answer on June 4, 2026 at 4:58 pm

    The second approach might work the following way:

    out.print(CONSTANT_STRING_PART_1);
    out.print(CONSTANT_STRING_PART_2);
    out.print(CONSTANT_STRING_PART_3);
    out.print(CONSTANT_STRING_PART_4);
    // ...
    out.print(CONSTANT_STRING_PART_N);
    out.println();
    

    You can do this in a loop of course (which is highly recommended ;)).

    The way you do it, you just temporarely create the large string again to then pass it to println(), which is the same problem as the first one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that has a file path: $workingFile = '/var/tmp/A/B/filename.log.timestamps.etc'; I want
Now I have a function that has to return a string. I saw a
I have mysql table that has a column that stores xml as a string.
I have this string that has illegal chars that I want to remove but
I have a String[] that has at least 2 elements. I want to create
I have a string that has a format like this: <b>*GTPersonnel</b><table border=1><tr><td>&#115;&#115;&#50;&#49;&#49;&#49;</td></tr></table> I want
I have a string that has several date values in it, and I want
I have a C++ program already formed that has a string that I want
If I have a string variable that has: C:\temp\temp2\foo\bar.txt and I want to get
I have a string that has the value of name:score . I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.