无法为JSP编译类:无法解析为类型 [英] Unable to compile class for JSP: cannot be resolved to a type

查看:223
本文介绍了无法为JSP编译类:无法解析为类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个动态网络项目。项目在本地服务器上运行良好但不在线上运行。在实时服务器上,它在我使用任何java对象的行抛出异常:

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:无法为JSP编译类:

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:

错误:

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.

请帮助。(在我的实时服务器上启用Tomcat)。

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

以下是实时服务器的链接
http://mutmanager.com/ webservice / groups.jsp

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

推荐答案

您好像忘记导入 CollectionAppService 在您的JSP中:

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

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

但是,存在一个主要问题,你不应该在JSP中加入Java代码。相反,您应该将代码移动到类并从Servlet或类似代码调用它。

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.

主要文章:

  • How to avoid Java Code in JSP-Files?

不要忘记学习是好的,但也要以正确的方式学习。

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

再次阅读你的问题后,我看到这个Stacktrace行:

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


找不到文件:/ Users / sukhpal / Data / Workspaces / J2EE Workspace / CollectionApp / build / classes / com / mut / service / common / Constants.class

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

我想你的问题是常量类(以及你的 CollectionApp )也在项目B中。你是使用来自包含这些类的另一个项目的绝对路径引用,也许你没有上传它。

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.

想象一下这种情况:你有一个web项目(项目A)和你有一些 已经在另一个项目(项目B)中完成繁重工作的类,您可以在大多数项目中重复使用这些项目。在开发环境中,您有从项目A到项目B的引用,但之后只将项目A上载到生产环境。这样,当项目A想要从项目B调用一个类时,它将永远不会找到它,并抛出异常。

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.

最佳解决方案:


  • 从项目B创建一个jar。

  • 在项目A中,删除对项目B的所有引用。

  • 将jar添加到项目A并在Build Path中设置。

  • 将项目A上传到生产。

  • 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.

这篇关于无法为JSP编译类:无法解析为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆