JSP 可变参数 IllegalArgumentException: wrong number of arguments

http://stackoverflow.com/questions/15560508/invoke-method-with-varargs-in-el-throws-java-lang-illegalargumentexception-wron
http://stackoverflow.com/questions/5033575/using-varargs-in-a-tag-library-descriptor
JSP DEBUG

以下表达式在Tomcat 7上运行没有异常,发布到 JBossEAP 6.2后总是报非法参数异常,究其原因是Tomcat EL parser支持可变参数,JBossEAP 6.2不支持。


${currentUser.isPermitAny("SUPPLIER_UPDATE_BASIC","SUPPLIER_UPDATE_INVOICE","SUPPLIER_UPDATE_PAYMENT")}'

public boolean isPermitAny(String... permissions){
    boolean[] ps = SecurityUtils.getSubject().isPermitted(permissions);
    for (boolean b : ps) {
        if(b) return true;
    }
    return false;
}

解决方法

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${currentUser.isPermitAny(fn:split("SUPPLIER_UPDATE_BASIC,SUPPLIER_UPDATE_INVOICE,SUPPLIER_UPDATE_PAYMENT",","))}

public boolean isPermitAny(String[] permissions){
    boolean[] ps = SecurityUtils.getSubject().isPermitted(permissions);
    for (boolean b : ps) {
        if(b) return true;
    }
    return false;
}

或者

${currentUser.isPermitAny("SUPPLIER_UPDATE_BASIC,SUPPLIER_UPDATE_INVOICE,SUPPLIER_UPDATE_PAYMENT")}

public boolean isPermitAny(String permissions){
    boolean[] ps = SecurityUtils.getSubject().isPermitted(StringUtils.split(permissions, ","));
    for (boolean b : ps) {
        if(b) return true;
    }
    return false;
}

你可能感兴趣的:(JSP 可变参数 IllegalArgumentException: wrong number of arguments)