SoulSkip 2014-09-02 13:15 采纳率: 0%
浏览 2160

我在读取Struts2源码的时候,不了解ActionMapper怎样读取通配符的?

在读取Struts2源码的时候~
public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) {
ActionMapping mapping = new ActionMapping();
String uri = RequestUtils.getUri(request);

    int indexOfSemicolon = uri.indexOf(";");
    uri = (indexOfSemicolon > -1) ? uri.substring(0, indexOfSemicolon) : uri;
    //去掉后缀
    uri = dropExtension(uri, mapping);
    if (uri == null) {
        return null;
    }
     //解析出方法名和命名空间
    parseNameAndNamespace(uri, mapping, configManager);
    //处理特殊的传递的参数,清除最后以。x或者。y作为后缀的属性,这个是为什么。难道是敏感词么?
    handleSpecialParameters(request, mapping);
    //最后返回过滤好的action的一些信息~这样的话,就能获取到Action的名称方法
    return parseActionName(mapping);
}

protected ActionMapping parseActionName(ActionMapping mapping) {
if (mapping.getName() == null) {
return null;
}
//这个的意思是获取index!getindex.action的时候获取Action 的名称与方法
//现在我想问一下如果是通配符的时候怎样处理呢?
//难道是需要通过读取struts.xml文件然后需找规律
if (allowDynamicMethodCalls) {
// handle "name!method" convention.
String name = mapping.getName();
int exclamation = name.lastIndexOf("!");
if (exclamation != -1) {
mapping.setName(name.substring(0, exclamation));

            mapping.setMethod(name.substring(exclamation + 1));
        }
    }
    return mapping;
}

****这个方法是解决 index!getindex.action的时候获取Action 的名称与方法的方法
但是如果配置文件中如果是
action name="user_*" class="com.test.action.UserAction" method="{1}">
/user_{1}.jsp

这样的情况下呢?怎样获取action 与MethodName呢?****

  • 写回答

2条回答 默认 最新

  • SoulSkip 2014-09-03 07:24
    关注

    我自己找到了答案了~自己回复~

    评论

报告相同问题?

悬赏问题

  • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?