Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Chisisi Massri   on Jul 08 In Java Category.

  
Question Answered By: Tracy Myers   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);
}

}

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

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