Unable to compile class for JSP: cannot allow type

I am developing a dynamic web project. The project runs on a local server, but not live. On a live server, it throws an exception on the line in which I 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(); 

Running the project on the local server, as well as errors in the 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 real server).

Below is the live server link http://mutmanager.com/webservice/groups.jsp

+4
source share
2 answers

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

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

But there is a big problem, you do not have to put Java code in your JSP. Instead, you should port your code to a class and call it from a servlet or similar.

The main article for this:

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


After you 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 assume that your problem is the Constant class (and your CollectionApp ) inside project B. You are using absolute references to the path from another project that contains these classes, and maybe you are not loading it.

Imagine this situation: you have a web project (project A), and you have several classes that are already doing hard and enjoyable work in another project (project B), which you reuse in most of the projects you work on . In your development environment, you have a link from project A to project B, but then you load project A into your production environment. Thus, when project A wants to call a class from project B, it will never find it, and an exception will be thrown.

The best solution:

  • Create a jar from project B.
  • In project A, delete all references to project B.
  • Add the jar to project A and install it in the build path.
  • Load your project A into production.
+5
source

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

You need to import user-defined classes using import

Example:

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

Source: https://habr.com/ru/post/1435146/


All Articles