473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML in servlet response

1
Hi,
I wonder if anyone can help with this question.
I have a test servlet that simply echoes back XML text that is sent to it, with UTF-8 encoding. Here's the servlet code:

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
ServletInputStream sis = request.getInputStream();
ServletOutputStream sos = response.getOutputStream();
//File file = new File("C:/echo.xml");
//FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[1024];
int i = 0;
while((i=sis.read(buf))!=-1) {
sos.write(buf, 0, i);
//fos.write(buf, 0, i);
}
sis.close();
sos.close();
//fos.close();
}

The XML text that arrives in the request has the header:
<?xml version="1.0" encoding="UTF-8"?>

The file output (commented out in the code above) shows the header:
<?xml version="1.0" encoding="UTF-8"?>

But the XML text that appears in the response has the header:
<?xml version="1.0"?>
The response header contains, as expected:
Content-Type: text/xml;charset=UTF-8


I'm assuming that this is some behavior of the ServletResponse interface.
If so:
- is this documented?
- is there any way to control/prevent it, so that the XML text in the response shows the same header?

Many thanks for any help/advice with this.
MKWG
Aug 21 '08 #1
1 12570
That sounds weird. As far as I know the servlet response data section contains exactly the bytes you write to it.

Are you using a browser to access the servlet ?

Are you 100% sure that the browser is not pretty printing the XML
and the removing the enconding attribute (it is redundant since UTF-8 is the standard encoding).

Try using netcat, curl or wget to access the servlet. This way you can be sure that nothing alters the data

/Christoffer
Aug 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve | last post by:
Does anyone know what is wrong with this code or why I might be experiencing this behavior? I have a Java application that submits HTTP POST requests to a servlet (with content in the body of...
1
by: Vasil Slavov | last post by:
I apologize for the long email. I hope somebody will have time to read it and give some suggestions. I am working on a school project written in Python (using mod_python) and I need to upload a...
3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
1
by: sang | last post by:
Hi I prepared a program for Email Integration. That is email send to others through servlet's. I gave the code but it has some error in my code. Please check the code and give the feedback. ...
0
by: ErikaW | last post by:
Hi all, I've tried to google this but could not find a clear solution. I have a Web application developed in JDevloper using mostly html and Javascript. I have a pre-defined PDF form which I merge...
14
by: ramadeviirrigireddy | last post by:
Hi All, I have the following code for form and servlet. when the form is submitted the servlet will print the values passed by the form. i'm not getting the servlet o/p when i submit the...
7
evilmonkey
by: evilmonkey | last post by:
My assignment was to create a shopping cart servlet, it works locally on tomcat but when I deploy it to the schools server (also tomcat) it fails to refresh the front page and just prints the HTML...
0
by: krishna81m | last post by:
Could some one please explain why the session is not being maintained when I am doing a forward in a servlet after setting a cookie. I am even unable to set session attributes or parameters and...
2
by: dmstn | last post by:
Hey! I've got a little problem. I have to make a web site for a university essay. I curently have to create a search engine. Users can enter a hotel name in a search bar and results have to appear in...
3
by: vijaykumardahiya | last post by:
Dear Sir, I have two queries. First question is: I have a Html page. On which Have two buttons Submit and Issue. I want when I click on Sumit button request should be go to submit.jsp. and When I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.