使用WebSphere Portal开发多区域设置网站
2010-09-27 08:17:29 来源:WEB开发网您还需要重写 getLocale 和 getLocales 方法,以返回与 getHeader 方法所返回的相同的区域设置。
清单 3. LocaleRequestWrapper getLocale() 和 getLocales() 方法
public Locale getLocale()
{
if (localeObj != null) return localeObj;
else
{
// get the original request
HttpServletRequest request = (HttpServletRequest)getRequest();
return request.getLocale();
}
}
public Enumeration getLocales()
{
if (locale != null) return Collections.enumeration(locales);
else
{
// get the original request
HttpServletRequest request = (HttpServletRequest)getRequest();
return request.getLocales();
}
}
开发和安装 Servlet 筛选器
现在您需要在 Servlet 筛选器(我们将其称为 LocaleServletFilter)中实例化 LocaleRequestWrapper,并将其传递给链中的下一个筛选器。您将开发一个 Servlet 筛选器来执行业务逻辑和确定区域设置。此区域设置用于构造 LocaleRequestWrapper,如清单 4 中所示。
清单 4. LocaleServletFilter 类
public class LocaleServletFilter extends javax.servlet.Filter
{
public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws java.io.IOException, javax.servlet.ServletException
{
HttpServletRequest httpRequest = (HttpServletRequest)request;
Locale locale = null;
// perform the business logic here to determine the locale of
// the request
// wrap the request with our locale request wrapper
LocaleRequestWrapper wrapper =
new LocaleRequestWrapper(httpRequest, locale);
// forward the wrapped request to the next filter in the chain
if (chain != null)
{
chain.doFilter(wrapper, response);
}
}
}
编缉推荐阅读以下文章
- 扩展WebSphere Portal V6个性化功能
更多精彩
赞助商链接