可以实现,但要麻烦几百倍:光写个HelloWorld只实现四个国家语言就要写这么多:<%@page language="java" contentType="text/plain; charset=UTF-8" import="java.text.*,java.io.*,java.util.*,javax.servlet.jsp.*"%>
<html>
<head>
<title>mul_language_HelloWorld</title>
</head>
<body>
<%!
Locale locale;
DateFormat format;
JspWriter writer;
%>
<%!
//中文
void processChinese() throws Exception {
locale = new Locale("zh", "");
format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
writer.println("Chinese:<br>");
writer.println("\u4f60\u597d\u4e16\u754c");
writer.println(format.format(new Date()));
writer.flush();
}
//英语
void processEnglish() throws Exception {
locale = new Locale("en", "US");
format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
writer.println("English:<br>");
writer.println("HelloWorld");
writer.println(format.format(new Date()));
writer.flush();
}
//韩语
void processKorea() throws Exception {
locale = new Locale("ko", "");
format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
writer.println("Korea:<br>");
writer.println("\uc548\ud558\uc138\uc694\uc138\uacc4");
writer.println(format.format(new Date()));
writer.flush();
}
%>
<%
//获得请求的语种
String language = request.getParameter("language");
int lan = Integer.parseInt(language);
writer = out;
switch (lan) {
case 1:
processChinese();
break;
case 2:
processEnglish();
break;
case 3:
processKorea();
break;
}
%>
</body>
</html>
<html>
<head>
<title>mul_language_HelloWorld</title>
</head>
<body>
<%!
Locale locale;
DateFormat format;
JspWriter writer;
%>
<%!
//中文
void processChinese() throws Exception {
locale = new Locale("zh", "");
format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
writer.println("Chinese:<br>");
writer.println("\u4f60\u597d\u4e16\u754c");
writer.println(format.format(new Date()));
writer.flush();
}
//英语
void processEnglish() throws Exception {
locale = new Locale("en", "US");
format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
writer.println("English:<br>");
writer.println("HelloWorld");
writer.println(format.format(new Date()));
writer.flush();
}
//韩语
void processKorea() throws Exception {
locale = new Locale("ko", "");
format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
writer.println("Korea:<br>");
writer.println("\uc548\ud558\uc138\uc694\uc138\uacc4");
writer.println(format.format(new Date()));
writer.flush();
}
%>
<%
//获得请求的语种
String language = request.getParameter("language");
int lan = Integer.parseInt(language);
writer = out;
switch (lan) {
case 1:
processChinese();
break;
case 2:
processEnglish();
break;
case 3:
processKorea();
break;
}
%>
</body>
</html>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货