I am migrating a web application from Weblogic to Liberty Profile. I get the error "List cannot be resolved to a type " When I look at the java class that was generated from the JSP, its missing the import for java.util.List.
This seems to be an issue with collections without generics: List alphabetIndexList = new ArrayList();
If I rewrite this to use generics, the error goes away: List alphabetIndexList = new ArrayList();
However, there is also a problem when using List and initializing to a List: List = getList(); (getList() return List)
So in this case it seems like the JSP precompiler is not adding the import for List, which may have something to do with the fact that its an interface.
There does not seem to be any setting in the element to control this behavior, perhaps its a bug?
THis worked with Weblogic and Tomcat.
I assume you meant that List alphabetIndexList = new ArrayList(); works?
Does the jsp have at the top?
Edit: meant to ask if it had this at the top, but the editor keeps throwing it away:
<%@page import="java.util.*"%>
YEs,
List<String> alphabetIndexList = new ArrayList<String>();
works.
HEre are the imports: package com.ibm._jsp;
import javax.servlet.; import javax.servlet.http.; import javax.servlet.jsp.*;
import com.dbo2.pipeline.view.util.PaginatedResultListVO; import com.dbo2.pipeline.view.contact.ContactListRowVO; import com.dbo2.pipeline.controller.contact.ContactAlterListAction; import com.dbo2.pipeline.view.company.CompanyForm;
Answer by gas (897) | Mar 31, 2015 at 10:49 AM
You need to add in your jsp files the following import directive (can be either with *
or with explicit java.util.List
and java.util.ArrayList
):
<%@page import="java.util.*"%>
WebLogic imports java.util.*
package implicitly in JSP which is not compliant with the JSP specification (see JSP.1.10.1 The page Directive) :
Packages java.lang.*, javax.servlet.*, javax.servlet.jsp.*, and javax.servlet.http.* are imported
implicitly by the JSP container. No other packages may be part of this implicitly imported list.