Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

internationalization problem!

  Asked By: Chisisi    Date: Jul 08    Category: Java    Views: 817
  

I have an Action Servlet which in some cases I have to throw an
Exception which its Message String is in Persian (a Language),I read
all
of the messages from a property file that I converted the Persian
messages to unicode by using native2ascii tool of JDK ;however
whenever I try to display it in a jsp page (which it's charset set to
UTF-8) it seems that its encoding is wrong .
Can anybody help me in this context

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Tracy Myers     Answered On: Jul 08

i hope this code sample help you :


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

public class ResourceServlet extends HttpServlet {

ResourceBundle rb = null;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html");

PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);

int localeSelected = 2;
String strTemp = request.getParameter("MyLanguage");
if (null != strTemp)
localeSelected = (new BigDecimal(strTemp)).intValue();

switch (localeSelected){
case 0 :
System.out.println("User Requested French Page");
rb = ResourceBundle.getBundle("LocaleStrings", Locale.FRENCH);
System.out.println(rb.toString());
break;

case 1 :
System.out.println("User Requested German Page");
rb = ResourceBundle.getBundle("LocaleStrings", Locale.GERMAN);
break;

case 2 :
default:
System.out.println("User Requested Default/English Page");
rb = ResourceBundle.getBundle("LocaleStrings", Locale.ENGLISH);
}


out.println("<html>");
out.println("<body>");

out.println("<head>");
String title = rb.getString("title");
out.println("<title>" + title + "</title>");
out.println("</head>");

out.println("<body>");
out.println(rb.getString("Question"));

out.println("</body>");
out.println("</html>");

out.println("</body>");
out.println("</html>");
}

public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}

}

 
Answer #2    Answered By: Vonda Ramirez     Answered On: Jul 08

Maybe You've forgot to run native2ascii like this : native2ascii -encoding UTF-8

 
Answer #3    Answered By: Bach-yen Nguyen     Answered On: Jul 08

do you want to use Property file wich contain farsi message ?
I had this problem when i wanted to Internationalize my application I
had property file which contain messages and I used ResourceBundle .
if your problem is the same reply me and i will explain my solution to
you

 
Answer #4    Answered By: Lurline Fischer     Answered On: Jul 08

u should set u'r jsp page Encoding to the utf-8
this is a familar error in multilingual project'S

 
Answer #5    Answered By: Fedde Bakker     Answered On: Jul 08

thanks but I did it as I said , I think the problem might caused by the Application Server which tries to encode it twise .

 
Didn't find what you were looking for? Find more on internationalization problem! Or get search suggestion and latest updates.