Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSP Scriptlet赢得';当我提供0个参数时,无法识别vararg方法_Java_Jsp_Variadic Functions - Fatal编程技术网

Java JSP Scriptlet赢得';当我提供0个参数时,无法识别vararg方法

Java JSP Scriptlet赢得';当我提供0个参数时,无法识别vararg方法,java,jsp,variadic-functions,Java,Jsp,Variadic Functions,我有一个带有签名的公共静态Java方法getMessage(字符串、区域设置、对象…),这意味着它将接受0到n个对象 我尝试从scriptlet中的JSP文件调用该方法。(我知道,JSP中的内联Java被认为是不好的做法,但我们很多10年前的web应用程序都是这样的。)服务器抛出一个NoSuchMethodException,声称com.mypackage.MyClass.getMessage(String,Locale)不存在 如果在区域设置之后向调用添加null参数,则效果良好。如果我添加一

我有一个带有签名的公共静态Java方法
getMessage(字符串、区域设置、对象…
),这意味着它将接受0到n个对象

我尝试从scriptlet中的JSP文件调用该方法。(我知道,JSP中的内联Java被认为是不好的做法,但我们很多10年前的web应用程序都是这样的。)服务器抛出一个
NoSuchMethodException
,声称
com.mypackage.MyClass.getMessage(String,Locale)
不存在

如果在区域设置之后向调用添加null参数,则效果良好。如果我添加一个与调用varags版本的
getMessage(String,Locale)
相匹配的包装器方法,它就可以正常工作。如果我从Java类调用它,它工作得很好。但是,如果我试图从JSP中的scriptlet中为varags方法提供0个参数,它将无法识别varags方法

这是jsp呈现代码中的错误,还是我在varargs实现中做错了什么

从MyClass.java:

private static org.springframework.context.ApplicationContext applicationContext;

public static String getMessage(String key, Locale locale, Object... args) {
    // This section isn't really relevant; this method doesn't even get called.
    String variant = locale.getVariant();
    if (variant != null && variant.length() > 0 && variant.charAt(0) == '_' && FooLocale.hasFooLocale(variant)) {
        FooLocale fooLocale = FooLocale.lookupFooLocale(variant);
        if (fooLocale.isChangedKey(key)) {
            return applicationContext.getMessage(key + '.' + variant, args, new Locale(locale.getLanguage(), locale.getCountry()));
        }
    }

    return applicationContext.getMessage(key, args, locale);
}

// Added this wrapper method because the above one wasn't working.
public static String getMessage(String key, Locale locale) {
    return getMessage(key, locale, (Object[])null);
}
从example.jsp:

<%-- This should use the vararg version if there's no wrapper.
But if the wrapper isn't present, this causes an error instead. --%>
<%= MyClass.getMessage("heading.ContactInfo", locale) %>

...

<%-- This should always use the vararg version --%>
<%= MyClass.getMessage("errors.InputIsInvalid", locale, "Name") %>

...

你能发布你的努力吗?我是说代码?据我所知,这只是JSP scriplets的一个缺陷或限制。如果有人找到了解决方案或答案,请发布。你能发布你的努力吗?我指的是代码?据我所知,这只是JSP scriplets的一个缺陷或局限性。如果有人找到解决方案或答案,请发布。