主要需要注意:
<%
request.setCharacterEncoding("ISO-8859-1");
String loc=getStr(request.getParameter("locale"));
%>
<%!
public String getStr(String str){
try{
String t = new String(str.getBytes("ISO-8859-1"),"UTF-8");
return t;
}catch(Exception e){}
return null;
}
%>
整个例子全部为:
<%@page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/WEB-INF/functions" prefix="f" %>

<%!
public String getStr(String str){
try{
String t = new String(str.getBytes("ISO-8859-1"),"UTF-8");
return t;
}catch(Exception e){}
return null;
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP Page</h1>
<jsp:plugin type="applet" code="DigitalClock.class" codebase="/JSPs" jreversion="1.4" align="center" height="25" width="300"
nspluginurl="http://java.sun.com/j2se/1.4/download.html"
iepluginurl="http://java.sun.com/j2se/1.4/download.html" >
<jsp:params>
<jsp:param name="language" value="<%=request.getLocale().getLanguage()%>" />
<jsp:param name="country" value="<%=request.getLocale().getCountry()%>" />
<jsp:param name="bgcolor" value="FFFFFF" />
<jsp:param name="fgcolor" value="CC0066" />
</jsp:params>
<jsp:fallback>
<p>Unable to start plugin.</p>
</jsp:fallback>
</jsp:plugin>
<%
request.setCharacterEncoding("ISO-8859-1");
String loc=getStr(request.getParameter("locale"));
%>
<jsp:useBean id="locales" scope="application" class="mypkg.MyLocales"/>
<form name="localeForm" action="index.jsp" method="post">
<p/>
<c:set var="selectedLocaleString" value="<%=loc%>" />
<c:set var="selectedFlag" value="${!empty selectedLocaleString}" />
<b>Locale:</b>
<select name=locale>
<c:forEach var="localeString" items="${locales.localeNames}" >
<c:choose>
<c:when test="${selectedFlag}">
<c:choose>
<c:when test="${f:equals(selectedLocaleString,localeString)}" >
<option selected>${localeString}</option>
</c:when>
<c:otherwise>
<option>${localeString}</option>
</c:otherwise>
</c:choose>
</c:when>
<c:otherwise>
<option>${localeString}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
<input type="submit" name="Submit" value="Get Date">
</form>
<p/>
<c:if test="${selectedFlag}" >
<jsp:setProperty name="locales" property="selectedLocaleString" value="${selectedLocaleString}" />
<jsp:useBean id="date" class="mypkg.MyDate"/>
<jsp:setProperty name="date" property="locale" value="${locales.selectedLocale}"/>
<b>Date: </b>${date.date}
</c:if>

</body>
</html>
注意一个问题:applet的代码不能放在WEB-INF中













整个例子全部为:

















































































注意一个问题:applet的代码不能放在WEB-INF中