Unable to compile class for JSP: cannot be resolved to a type

27,894

It looks like you forgot to import your CollectionAppService in your JSP:

<%@ page import="your.package.CollectionAppService" %>

But, there is a major problem, you should not put Java code in your JSP. Instead, you should move your code to a class and invoke it from a Servlet or similar.

Main article for this:

Do not forget that learning is good, but also learning in the right way.


After read your question again, I see this Stacktrace line:

File not found: /Users/sukhpal/Data/Workspaces/J2EE Workspace/CollectionApp/build/classes/com/mut/service/common/Constants.class

I guess that your problem is Constant class (and your CollectionApp as well) is inside a project B. You're using absolute path references from another project that contains these classes and maybe you're not uploading it.

Imagine this situation: You have a web project (project A) and you have some classes that already do a heavy and fancy job in another project (project B) that you reuse on most projects you work on. In your development environment, you have a reference from project A to project B, but then you only upload project A to your production environment. In this way, when project A wants to call a class from project B, it will never find it, and the exception is thrown.

The best solution:

  • Create a jar from project B.
  • In project A, remove all the references to project B.
  • Add the jar into project A and set it in the Build Path.
  • Upload your project A to production.
Share:
27,894
Sukhpal Singh
Author by

Sukhpal Singh

Updated on September 23, 2020

Comments

  • Sukhpal Singh
    Sukhpal Singh over 3 years

    I am developing a Dynamic web project. Project is running well on local server but not on live. On live server it throws exception at the line I have used any java object:

    org.apache.jasper.JasperException: Unable to compile class for JSP:

        An error occurred at line: 7 in the jsp file: /groups.jsp
    CollectionAppService cannot be resolved to a type
    4: <%
    5:  String json = "[]";
    6:  try {
    7:      CollectionAppService collectionAppService = new CollectionAppService();
    8:      json = collectionAppService.getGroupsJson();
    9:  } catch (Exception e) {
    10:         e.printStackTrace();
    

    Project run on local server but also have errors in error log for max class files:

    Error:

    Thu Sep 20 01:16:11 GMT+05:30 2012
    File not found: /Users/sukhpal/Data/Workspaces/J2EE Workspace/CollectionApp/build/classes/com/mut/service/common/Constants.class.
    

    Please help.(Tomcat is enabled on my live server).

    Following is link of live server http://mutmanager.com/webservice/groups.jsp