请问如何在Eclipse for J2EE平台中配置properties文件?代码如下:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.io.*, java.util.*, java.awt.*"%><%
String languageDefault = Locale.getDefault().getLanguage();
String countryDefault = Locale.getDefault().getCountry();
Locale defaultLocale = null;
String charset = null;
if(languageDefault == "en" || languageDefault.equals("en")) {
defaultLocale = Locale.ENGLISH;
charset = "ISO-8859-1";
} else if(countryDefault == "CN" || countryDefault.equals("CN")) {
defaultLocale = Locale.SIMPLIFIED_CHINESE;
charset = "gb2312";
} else if(countryDefault == "TW" || countryDefault.equals("TW")) {
defaultLocale = Locale.TRADITIONAL_CHINESE;
charset = "big5";
} else
System.out.println("Unknown Language.");
if(session.isNew()) {
session.setAttribute("locale", defaultLocale);
session.setAttribute("charset", charset);
} else {
String language = request.getParameter("language");
if(language == null || language.equals("null")) {
session.setAttribute("locale", defaultLocale);
session.setAttribute("charset", charset);
} else {
if(language.equals("Locale.SIMPLIFIED_CHINESE") || language.equals("Locale.SIMPLIFIED_CHINESE")) {
session.setAttribute("locale", Locale.SIMPLIFIED_CHINESE);
session.setAttribute("charset", "gb2312");
} else if(language.equals("Locale.TRADITIONAL_CHINESE") || language.equals("Locale.TRADITIONAL_CHINESE")) {
session.setAttribute("locale", Locale.TRADITIONAL_CHINESE);
session.setAttribute("charset", "big5");
} else if(language.equals("Locale.ENGLISH") || language.equals("Locale.ENGLISH")) {
session.setAttribute("locale", Locale.ENGLISH);
session.setAttribute("charset", "ISO-8859-1");
}
}
}
Locale locale = (Locale)session.getAttribute("locale");
ResourceBundle messagesBundle = ResourceBundle.getBundle("NewFile", locale);
String localeCountry = locale.getCountry();
String localeLanguage = locale.getLanguage();
System.out.println("locale: " + locale.toString());
System.out.println("localeCountry: " + locale.getCountry());
System.out.println("localeLanguage: " + locale.getLanguage());
if(localeLanguage == "en") response.setContentType("text/html; charset=ISO-8859-1");
else if(localeCountry == "CN") response.setContentType("text/html; charset=gb2312");
else if(localeCountry == "TW") response.setContentType("text/html; charset=big5");
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
<base target="contents" />
</head>
<body topmargin="0" leftmargin="0">
<table border="0" width="796" height="60" style="font-size: 10pt" cellspacing="0" cellpadding="0">
<tr rowspan="5">
<td colspan="3"> </td>
</tr>
<tr rowspan="5">
<td colspan="3"> </td>
</tr>
<tr>
<td width="196" height="68"></td>
<td width="470" height="64">
<p align="center">
<a href="#" onclick="href='NewFile.jsp?language=Locale.SIMPLIFIED_CHINESE'">
<%=messagesBundle.getString("simplifiedChinese") %>
</a> |
<a href="#" onclick="href='NewFile.jsp?language=Locale.TRADITIONAL_CHINESE'">
<%=messagesBundle.getString("traditionalChinese") %>
</a> |
<a href="#" onclick="href='NewFile.jsp?language=Locale.ENGLISH'">
<%=messagesBundle.getString("english") %>
</a>
</p>
</td>
<td>
<p align="center">
<%=messagesBundle.getString("username") %>
</p>
</td>
</tr>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.io.*, java.util.*, java.awt.*"%><%
String languageDefault = Locale.getDefault().getLanguage();
String countryDefault = Locale.getDefault().getCountry();
Locale defaultLocale = null;
String charset = null;
if(languageDefault == "en" || languageDefault.equals("en")) {
defaultLocale = Locale.ENGLISH;
charset = "ISO-8859-1";
} else if(countryDefault == "CN" || countryDefault.equals("CN")) {
defaultLocale = Locale.SIMPLIFIED_CHINESE;
charset = "gb2312";
} else if(countryDefault == "TW" || countryDefault.equals("TW")) {
defaultLocale = Locale.TRADITIONAL_CHINESE;
charset = "big5";
} else
System.out.println("Unknown Language.");
if(session.isNew()) {
session.setAttribute("locale", defaultLocale);
session.setAttribute("charset", charset);
} else {
String language = request.getParameter("language");
if(language == null || language.equals("null")) {
session.setAttribute("locale", defaultLocale);
session.setAttribute("charset", charset);
} else {
if(language.equals("Locale.SIMPLIFIED_CHINESE") || language.equals("Locale.SIMPLIFIED_CHINESE")) {
session.setAttribute("locale", Locale.SIMPLIFIED_CHINESE);
session.setAttribute("charset", "gb2312");
} else if(language.equals("Locale.TRADITIONAL_CHINESE") || language.equals("Locale.TRADITIONAL_CHINESE")) {
session.setAttribute("locale", Locale.TRADITIONAL_CHINESE);
session.setAttribute("charset", "big5");
} else if(language.equals("Locale.ENGLISH") || language.equals("Locale.ENGLISH")) {
session.setAttribute("locale", Locale.ENGLISH);
session.setAttribute("charset", "ISO-8859-1");
}
}
}
Locale locale = (Locale)session.getAttribute("locale");
ResourceBundle messagesBundle = ResourceBundle.getBundle("NewFile", locale);
String localeCountry = locale.getCountry();
String localeLanguage = locale.getLanguage();
System.out.println("locale: " + locale.toString());
System.out.println("localeCountry: " + locale.getCountry());
System.out.println("localeLanguage: " + locale.getLanguage());
if(localeLanguage == "en") response.setContentType("text/html; charset=ISO-8859-1");
else if(localeCountry == "CN") response.setContentType("text/html; charset=gb2312");
else if(localeCountry == "TW") response.setContentType("text/html; charset=big5");
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
<base target="contents" />
</head>
<body topmargin="0" leftmargin="0">
<table border="0" width="796" height="60" style="font-size: 10pt" cellspacing="0" cellpadding="0">
<tr rowspan="5">
<td colspan="3"> </td>
</tr>
<tr rowspan="5">
<td colspan="3"> </td>
</tr>
<tr>
<td width="196" height="68"></td>
<td width="470" height="64">
<p align="center">
<a href="#" onclick="href='NewFile.jsp?language=Locale.SIMPLIFIED_CHINESE'">
<%=messagesBundle.getString("simplifiedChinese") %>
</a> |
<a href="#" onclick="href='NewFile.jsp?language=Locale.TRADITIONAL_CHINESE'">
<%=messagesBundle.getString("traditionalChinese") %>
</a> |
<a href="#" onclick="href='NewFile.jsp?language=Locale.ENGLISH'">
<%=messagesBundle.getString("english") %>
</a>
</p>
</td>
<td>
<p align="center">
<%=messagesBundle.getString("username") %>
</p>
</td>
</tr>
</table>
</body>
</html>
解决方案 »
- 如何写满足这样需求的正则表达式??
- 程序在执行getHibernateTemplate().find()语句,报空指针异常
- TOMCAT5.5在WIN2003里面配置问题
- JSP如何获得当前路径?
- 求教一个编码问题
- 一个棘手的上传问题~~请教高手指导
- 如果我想定期访问数据库删除数据,该如何实现呢?请大家献计献策!!小弟我不胜感激!解决分全送!
- mysql中如何使用sql语句,使某一字段重命名;使某一字段数据类型改变
- String str; 和 String str = new String();有什么不同
- 为什么我的iPlanet Application Server不能正确的使用css?
- jsp处理多国语言的问题
- java設計分布式系統
不然的话楼上的你说怎么实现呢?求教 了