我对JSTL格式库有疑问。当我更改并单击指向其他子页面的链接时,它将使用默认语言(不是我选择的语言)返回我的网站。
我有四个带有消息的文件:
mylabels_pl_PL.properties
mylabels_zh_CN.properties
mylabels_de_DE.properties
mylabels.properties
Web应用程序的入口点是文件:index.jsp
内容:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="theLocale" value="${not empty param.theLocale ? param.theLocale : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${theLocale}" />
<fmt:setBundle basename="multilanguage.mylabels" />
<!DOCTYPE html>
<html>
<head>
<title>
<fmt:message key="label.title" />
</title>
<link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/index.js" async></script>
</head>
<body onload="assignDestinationForm()">
<header class="languages">
<nav>
<ul>
<li>
<a href="index.jsp?theLocale=en_EN">
<img src="img/england.jpg" alt="" id="imgEngland">
</a>
</li>
<li>
<a href="index.jsp?theLocale=de_DE">
<img src="img/germany.jpg" alt="" id="imgGermany">
</a>
</li>
<li>
<a href="index.jsp?theLocale=pl_PL">
<img src="img/poland.jpg" alt="" id="imgPoland">
</a>
</li>
</ul>
</nav>
</header>
<div style="clear: both;"></div>
<header class="title">
<h1>
<fmt:message key="label.title" />
</h1>
</header>
<article>
<section>
</section>
</article>
<div id="container">
<form id="myForm" action="">
<button id="btnSignIn">
<fmt:message key="label.login" />
</button>
<button id="btnSignUp">
<fmt:message key="label.register" />
</button>
</form>
</div>
<footer>
<fmt:message key="label.footer" />
</footer>
</body>
第二个子页面:login-form.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:set var="theLocale" value="${not empty param.theLocale ? param.theLocale : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${theLocale}" />
<fmt:setBundle basename="multilanguage.mylabels" />
<!DOCTYPE html>
<html>
<head>
<title>
<fmt:message key="label.login" />
</title>
<link rel="stylesheet" type="text/css" href="css/login-form.css">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/index.js"></script>
</head>
<body onload="assignDestinationForm()">
<header class="languages">
<nav>
<ul>
<li>
<a href="login-form.jsp?theLocale=en_EN">
<img src="img/england.jpg" id="btnEngland" alt="">
</a>
</li>
<li>
<a href="login-form.jsp?theLocale=de_DE">
<img src="img/germany.jpg" id="btnGermany" alt="">
</a>
</li>
<li>
<a href="login-form.jsp?theLocale=pl_PL">
<img src="img/poland.jpg" id="btnPoland" alt="">
</a>
</li>
</ul>
</nav>
</header>
<article>
<section>
<h1>
<fmt:message key="label.login" />
</h1>
<div id="container">
<form action="" method="get">
<fmt:message key="label.username" /> <br />
<input type="text" name="userName" id="userName">
<br /><br />
<fmt:message key="label.password" /> <br />
<input type="password" name="password" id="password">
<br /><br />
<button id="btnForm">
<fmt:message key="label.btnLogin" />
</button>
</form>
</div>
</section>
</article>
<footer>
<fmt:message key="label.footer" />
</footer>
</body>
我已经有了register-form.jsp页面,但是只有用于注册的表单,看起来类似于login-form.jsp。
在单击带有国家标志的图像后,如何设置指定的语言,然后在单击login-form.jsp的链接后,将其设置为相同的语言?