dcsimg
Language specific characters are not displayed correctly
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Fernando_OstanelLi
Posted On:   Wednesday, December 12, 2001 06:21 AM

TestCharset When I set a variable with the special chars used in the Portuguese language and then print it´s content to the terminal or to the HTML page, the result is ???????? instead of the correct chars. Here goes my test code: import java.util.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class TestCharset extends HttpServlet { public void doGet (HttpServletRequest Request, HttpServletResponse response) throws ServletException, IOException { try { Locale brazil =new Locale("pt", "BR"); Locale br = new Locale("pt"   More>>
TestCharset

When I set a variable with the special chars used in the Portuguese language and then print it´s content to the terminal or to the HTML page, the result is ???????? instead of the correct chars.
Here goes my test code:


import java.util.*;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;


public class TestCharset extends HttpServlet {


public void doGet (HttpServletRequest
Request,
HttpServletResponse response)
throws ServletException,
IOException {


try {


Locale brazil =new Locale("pt", "BR");

Locale br = new Locale("pt", "BR");

br.setDefault(brazil);

response.setContentType("text/html;
charset=ISO-8859-1");

response.setLocale(br);

String testSpecialChars =
"áéíóúçâêôãõàü ÁÉÍÓÚÇÂÊÔÃÕÀÜ";


System.out.println("output to
terminal : " +
testSpecialChars);


PrintWriter out =response.getWriter();

out.println(" ");
out.println(" ");
out.println("
Servlet ");
out.println(" ");
out.println(" ");
out.println("output to HTML: " +
testSpecialChars);
out.println(" ");
out.println(" ");
out.close();

} catch (Exception e) {
e.printStackTrace();
}

}
}

------------------
When I run the servlet above, the result is:

in the terminal window:
# output to terminal : ????????????? ?????????????

in the HTML page:
output to HTML: ????????????? ?????????????

Have you ever seen anything similar to that ?
Do you have an idea of what could be the reason for the problem ?
Do you believe it has something to do
to my OS Environment * ??

*(I´m running the application in Sun Solaris, Apache WebServer with Tomcat)

PS:
When recovering the content of a HTML field and printing it to the HTML
page, the characters are displayed correclty.
When requesting a page directly under the Apache Htdocs folder: like
index.html (or anything else is static, not generated by any servlet) it
works to.

Thanks in advance for consideration

Fernando

   <<Less

Re: Language specific characters are not displayed correctly

Posted By:   dumpu_lopez  
Posted On:   Friday, January 4, 2002 10:24 AM

Hello Fernando.

I try your code with the little modification. And all is ok. I have the next envoronment.

Windows 2000 Advanced Server
Servlet Exec 4.1
Servlet API 2.3

But maybe the problems is inside of your Servlet Content or in your O.S.

Also I have problems with more or less the same case.

My problem is when I am submited the information into the my DB(Oracle 8.1.5) and when use getParameter.

I have a class that use getBytes(), and use the correct encoder.

I try my class alone and work fine but Inside of my servlet something is bad, because Is not possible obtaind the correct characters for Portuguese or Spanish.

I try with setCharacterEncoding and also I don´t have the correct output.

Is very strange.?. If you have problems for obtain values from a database and put on the html pages, please send me a e-mail for miguel.ulloa@gedas.com.mx

Bye.

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

public class TestCharset extends HttpServlet
{
public void doGet (HttpServletRequest Request, HttpServletResponse response) throws ServletException, IOException
{ try
{
/*Locale brazil =new Locale("pt", "BR");
Locale br = new Locale("pt", "BR");*/
Locale brazil =new Locale("ISO-8859-1","");
Locale br = new Locale("ISO-8859-1","");
br.setDefault(brazil);
response.setContentType("text/html; charset=ISO-8859-1");
response.setLocale(br);
String testSpecialChars = "áéíóúçâêôãõàü ÁÉÍÓÚÇÂÊÔÃÕÀÜ";
System.out.println("output to terminal : " + testSpecialChars);
PrintWriter out =response.getWriter(); out.println("");
out.println(" ");
out.println("TestCharset Servlet");
out.println(" ");
out.println("");
out.println("output to HTML: " + testSpecialChars);
out.println("");
out.println("");
out.close();
} catch (Exception e)
{
e.printStackTrace();
}
}
}
About | Sitemap | Contact