论坛首页 Java企业应用论坛

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

浏览 1910 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-01-19  

  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 的常量配置

 

 

 

 

 

 

 

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics