Sitemesh整合struts2使用多个装饰器(非/*)的BUG修正

Bug报告地址: http://jira.opensymphony.com/browse/SIM-127

Bug描述: 在和sitemesh和struts整合使用时, 由于request.getRequestURI()得到的是请求的路径(浏览器地址栏输入的路径), 而通过request.getPathInfo()得到的确实配置的实际页面的路径, 因此, 根据sitemesh的com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper.getDecorator(HttpServletRequest, Page)这个方法的处理不能得到有效的装饰器配置.

涉及源代码:

public Decorator getDecorator(HttpServletRequest request, Page page) { String thisPath = request.getServletPath(); // getServletPath() returns null unless the mapping corresponds to a servlet if (thisPath == null) { String requestURI = request.getRequestURI(); if (request.getPathInfo() != null) { // strip the pathInfo from the requestURI thisPath = requestURI.substring(0, requestURI.indexOf(request.getPathInfo())); } else { thisPath = requestURI; } } String name = null; try { name = configLoader.getMappedName(thisPath); } catch (ServletException e) { e.printStackTrace(); } Decorator result = getNamedDecorator(request, name); return result == null ? super.getDecorator(request, page) : result; }

处理方案(此种解决方案经过测试在使用一级目录配置装饰器的时候工作良好.):

public Decorator getDecorator(HttpServletRequest request, Page page) { String thisPath = request.getServletPath(); // getServletPath() returns null unless the mapping corresponds to a // servlet if (thisPath == null) { String requestURI = request.getRequestURI(); if (request.getPathInfo() != null) { // strip the pathInfo from the requestURI thisPath = requestURI.substring(0, requestURI.indexOf(request .getPathInfo())); } else { thisPath = requestURI; } } else { thisPath = request.getRequestURI(); } String name = null; try { name = configLoader.getMappedName(thisPath); } catch (ServletException e) { e.printStackTrace(); } Decorator result = getNamedDecorator(request, name); return result == null ? super.getDecorator(request, page) : result; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值