我正在构建一个多语言应用程序,并且存储cookie中使用的最新语言的值。xpages SSJS:无法摆脱日志中的“com.ibm.xsp.acl.RedirectSignal”警告
当用户打开应用程序时,sessionScope变量未设置,代码将查找cookie值,如果不在正确的Locale中,则重新加载页面。
每当页面重新加载到正确的语言环境时,我都会收到“com.ibm.xsp.acl.RedirectSignal”警告,并且我会尽量避免它。
我的代码在我使用的应用程序中ApplicationLayout控制的beforeRenderResponse事件,看起来是这样的:
if(!sessionScope.lang) { //this only happens when the page is opened in browser for the first time
var lang = context.getUrlParameter("lang").toLowerCase();
if(!!lang) {
sessionScope.lang = lang.toUpperCase();
//set cookie for next time the site is opened by user
setCookie("lang", lang.toUpperCase(), 30);
context.setLocale(new Locale(lang.toLowerCase()));
} else {
//set language from cookie
var lang = getLangFromCookie();
if(!!lang) {
sessionScope.lang = lang;
context.setLocale(new Locale(lang.toLowerCase()));
} else {
sessionScope.lang = Appconfig.defaultLang;
context.setLocale(new Locale(Appconfig.defaultLang.toLowerCase()));
}
}
//need to trpa the redirect error thrown here, as it is just a warning - avoid filling log with this
//importPackage(com.ibm.xsp.acl.RedirectSignal);
importPackage(com.ibm.xsp.acl.RedirectSignal);
try {
//reload the page so Locale value kicks in
context.reloadPage();
} catch (RedirectSignal rs) {
//just ignore
}
}
即使我加了importPackage线,我仍然得到一个错误,当节省代码(这是在脚本库):
在行遇到“‘RS’” ......
我怎样才能使这项工作?
感谢:D
工程就像一个魅力,我没有看到日志中的重定向消息了。不知道为什么我收到了这条消息,但是从我读到的内容来看,它似乎可能是一个页面重定向到自己的时候。如果是这种情况,那么这是一个预期的行为,因为我确实在重新加载同一页面后,更改了区域设置,因此页面将以正确的语言重新加载。无法只使用浏览器的语言环境,我需要用户(或URL参数,甚至cookie)来选择他的语言环境,而不依赖于浏览器。 –