我按照本指南做了一个 JSTL JSP i18N如何国际化 Java Web 应用程序?但是,我无法设置默认语言,每次正文加载(onload)时我都使用 < c : set> 设置默认语言,但是当我刷新页面时它会随机显示语言。
你能给我默认语言的想法吗?
<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmtlang:setLocale value="${language}" />
<fmtlang:setBundle basename="com.example.i18n.text" var="lang" />
<script>
function setFR()
{
<c:set var="language" scope="session" value="fr"/>
}
function setEN()
{
<c:set var="language" scope="session" value="en"/>
}
function setES()
{
<c:set var="language" scope="session" value="es"/>
}
</script>
<html lang="${language}">
<body onload="setFR()">
<div id="all">
<img src="img/contentlogin.jpg"/>
<div id="language">
<form id="formLang" name="formlang">
<button type="submit" style="border: 0; background: transparent" id="language" name="language" value="fr" ${language == 'fr' ? 'selected' : ''}>
<img src="icon/fr.png" width="32" height="32" alt="submit" />
</button>
<button type="submit" style="border: 0; background: transparent" id="language" name="language" value="en" ${language == 'en' ? 'selected' : ''}>
<img src="icon/us.png" width="32" height="32" alt="submit" />
</button>
<button type="submit" style="border: 0; background: transparent" id="language" name="language" value="es" ${language == 'es' ? 'selected' : ''}>
<img src="icon/es.png" width="32" height="32" alt="submit" />
</button>
</form>
</div>
<form id="form1" name="form1" method="post" action="<%=appPath%>/loginAction">
<div id="info">
<span><fmtlang:message key="login.span.pleaseenterinfo" bundle="${lang}"/></span>
</div>
<div id="username_label">
<span><fmtlang:message key="login.label.username" bundle="${lang}"/></span>
</div>
<div id="username">
<input type="text" maxlength="15" STYLE="color: #3c7033; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #ebf7ca;" name="username" id="username" size="22">
</div>
<div id="password_label">
<span><fmtlang:message key="login.label.password" bundle="${lang}"/></span>
</div>
<div id="password">
<input type="password" STYLE="color: #3c7033; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #ebf7ca;" id ="password" name="password" size="22">
<input type="hidden" id ="language" name="language" value=<c:out value="${language}"/> size="22">
</div>
<div id="forgetpassword">
<span><fmtlang:message key="login.span.forget" bundle="${lang}"/></span>
</div>
<div id="forcea">
<img src="img/forceacopyright.png"/>
</div>
<div id="buttonlogin">
<button type="submit" style="border: 0; background: transparent" >
<img src="img/login.png" alt="12" width="101" height="94" border="0" />
</button>
</div>
<div id="wronguandp">
<%if(message!=null){ %>
<b><span style="color: red;"> <fmtlang:message key="login.wrong.display" bundle="${lang}"/></span></b>
<%}%>
</div>
</form>
</div>
</body>