By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Servlet reponse give incorrect euro sign (?) character.. HELP!

P: n/a
SPG
Hi,

I am haveing some problems with getting the correct XML response from a
Servlet.
I have data that contains the euro sign ( 0x80 = ?) and the string I am
trying to print out to the response definitely has the correct formatting..
Here is some sample code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class EncodingServlet extends HttpServlet implements
SingleThreadModel {
private static final String CONTENT_TYPE =
"text/xml;charset='iso-8859-1'";
private static String OUTPUT_XML = "<TEST val=\"24 / ?40\"><STRING>24
/ ?40</STRING></TEST>";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
out.println(OUTPUT_XML);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}

As you can see, the string contains the euro sign, but the response always
replaces it with a '?'.
I have been battling with this one all day, is there anyone that can help
me?

Steve
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
SPG
Hmm... As ypou can see.. Even the NG server has re-encoded the bloody
character!
Needles to say, the char code is 0x80

Cheers.

"SPG" <st************@nopoo.blueyonder.co.uk> wrote in message
news:ks*********************@news-text.cableinet.net...
Hi,

I am haveing some problems with getting the correct XML response from a
Servlet.
I have data that contains the euro sign ( 0x80 = ?) and the string I am
trying to print out to the response definitely has the correct formatting.. Here is some sample code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class EncodingServlet extends HttpServlet implements
SingleThreadModel {
private static final String CONTENT_TYPE =
"text/xml;charset='iso-8859-1'";
private static String OUTPUT_XML = "<TEST val=\"24 / ?40\"><STRING>24 / ?40</STRING></TEST>";

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
out.println(OUTPUT_XML);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}

As you can see, the string contains the euro sign, but the response always
replaces it with a '?'.
I have been battling with this one all day, is there anyone that can help
me?

Steve

Jul 17 '05 #2

P: n/a
SPG wrote:
Hmm... As ypou can see.. Even the NG server has re-encoded the bloody
character!
Needles to say, the char code is 0x80


What character encoding are you using? In ISO 8859-15 or Unicode, the euro
sign is 164 (0xa4) IIRC.

--
Chris Gray ch***@kiffer.eunet.be
/k/ Embedded Java Solutions

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.