读书人

Struts2.0中关于自定义映射器的扩张Ac

发布时间: 2012-10-26 10:30:59 作者: rapoo

Struts2.0中关于自定义映射器的扩展ActionMapper进行URL中编码设置

? Struts2.0 采用默认的映射器为DefaultActionMapper:

public class DefaultActionMapper implements ActionMapper

??? protected static final String METHOD_PREFIX = "method:";

??? protected static final String ACTION_PREFIX = "action:";

??? protected static final String REDIRECT_PREFIX = "redirect:";

??? protected static final String REDIRECT_ACTION_PREFIX = "redirectAction:";

?

扩展如下:

public class EncodedActionMapper extends DefaultActionMapper {
??? @Override
??? public String getUriFromActionMapping(ActionMapping mapping) {
??????? try {
??????????? return URLEncoder.encode(super.getUriFromActionMapping(mapping), "UTF-8").replaceAll("%2F", "/");
??????? } catch (UnsupportedEncodingException e) {
??????????? // ignore
??????????? return null;
??????? }
??? }
}

?

在Struts2.0中配置Action映射器的采用的非默认映射类

# struts.custom.properties=application,com/webwork/extension/custom

struts.mapper.class=com.unutrip.callcenter.web.ext.EncodedActionMapper

?

也可以在struts.xml 的常量配置

?

?

?

?

?

?

?

读书人网 >软件架构设计

热点推荐