我有一个场景,
当请求来自IE浏览器然后显示login
(这是默认行为),当它来自Chrome浏览器然后显示login_chrome
(布局定义在Tiles.xml中,如下所示)
<definition name="login" path="/login/login1.jsp"></definition>
<definition name="login_chrome" path="/login/login2.jsp"></definition>
我有CustomizedTileProcessor
public class CustomizedTileProcessor extends TilesRequestProcessor
{
@Override
protected boolean processTilesDefinition(String pDefinitionName, boolean pContextRelative, HttpServletRequest pRequest, HttpServletResponse pResponse) throws IOException, ServletException
{
if (isChromeBrowser(pRequest))
{
pDefinitionName+="_chrome";
}
return super.processTilesDefinition(pDefinitionName, true, pRequest, pResponse);
}
}
注意:我不想在JSP中放置逻辑来根据条件选择包含的JSP。
请帮帮我,告诉我覆盖TilesRequestProcessor
哪种方法可以动态更改切片定义?
答案 0 :(得分:0)
经过大量试验和错误后,我知道我必须覆盖processForwardConfig
TilesRequestProcessor
方法。在那里,我必须将path
对象的ForwardConfig
值的值覆盖到我的新布局,即login_chrome
。
请参阅以下代码:
public class CustomizedTileProcessor extends TilesRequestProcessor
{
@Override
protected void processForwardConfig(HttpServletRequest pRequest,
HttpServletResponse pResponse, ForwardConfig pForward)
throws IOException, ServletException
{
if(isChromeBrowser(pRequest))
{
ForwardConfig newForward = new ForwardConfig(pForward.getName(),
pForward.getPath()+"_chrome", pForward.getRedirect(),
pForward.getContextRelative());
super.processForwardConfig(pRequest, pResponse, newForward);
}
else
{
super.processForwardConfig(pRequest, pResponse, pForward);
}
}
}