Sukhpal Singh
Sukhpal Singh

Reputation: 730

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

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

Upvotes: 7

Views: 28652

Answers (2)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85789

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.

Upvotes: 6

kosa
kosa

Reputation: 66657

It seems you are missing import statement on top of the JSP

You need to import user defined classes using import

Example:

<%@ page import="yourpackage.CollectionAppService" %>

Upvotes: 0

Related Questions