0
votes

I have randomly started to get

"javax.el.ELException:"

error in jsp pages where we load the Java code. The same was working earlier but started to give this error randomly. Have tried building with different versions of JDK, tomcat and maven but the problem still persist. Any leads will be appreciated. Find the logs below:

Mar 05, 2014 3:22:31 PM org.apache.catalina.core.ApplicationDispatcher invoke SEVERE: Servlet.service() for servlet jsp threw exception javax.el.ELException: Cannot convert abcCache of type class java.lang.String to class java.lang.Class at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420) at org.apache.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:47) at javax.el.BeanELResolver.invoke(BeanELResolver.java:469) at org.apache.jasper.el.JasperELResolver.invoke(JasperELResolver.java:139) at org.apache.el.parser.AstValue.getValue(AstValue.java:173) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:963) at

1
Cannot convert shippingProvidersCache of type class java.lang.String to class java.lang.Class show the tag where you're handling the shippingProvidersCache on the JSP and what kind of a value you're assigning to said variable on your controller.t0mppa
Post your code used in JSP that gives this error.Luiggi Mendoza
The block of code in JSP giving the error is below: <c:forEach items="${cache.getCache('abcCache').someMethod()}" var="categoryMap"> <optgroup label="${categoryMap.key}"> <c:forEach items="${categoryMap.value }" var="category"> <option value="${category.categoryUrl}">${category.categoryName} - ${categoryMap.key }</option> </c:forEach> </optgroup> </c:forEach> In Java I have Cache which does CacheManager.getInstance().getCache(abcCache.class).someMethod()Ankur Choudhary

1 Answers

2
votes

The issue is with calling overloaded Java methods from JSP where the intended method won't be picked.

e.g. Illustration.java

getData(String input){
  // Code removed for simplicity 
}
getData(Class input){
  //Code removed for simplicity
}

Here, the jsp code getData("validInput") can pickup the second method with class parameter. Hence, the exception Cannot convert abcCache of type class java.lang.String to class java.lang.Class

Changing the second method to below solves the issue.

 getDataFromClass(Class input){
  //Code removed for simplicity
 }

The problem might occur randomly with different versions of JDK/Maven/Tomcat.

As a practice, one can think of having methods with different names, if to be used in such cases.