从JSP

时间:2015-10-25 14:43:12

标签: java eclipse jsp

在eclipse中,我试图将外部项目A中的类导入另一个项目B的JSP页面。

我在项目B中创建了一个类,我在其中调用了几个A方法,一切似乎都运行良好:没有错误,结果是连贯的......

但是当我像这样导入项目B JSP时:

<%@page import="com.project_A_package.*" %>

然后调用这样的方法,例如

<%= Project_A_Class.project_A_static_method() %>

Tomcat表示它无法识别Project_A_Class

Project_A_Class.cannot be resolved to a type

在第二个场景中,我甚至在JSP中调用了我在项目B中创建的类,该类成功地从项目A中提取结果,这次我得到了这个错误(顺便说一下,是&#34; com / project_A_package / Project_A_Class&#34;正常?):

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



root cause 
javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/project_A_package/Project_A_Class
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
    org.apache.jsp.project_B_jsp._jspService(project_B_jsp.java:82)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



root cause 
java.lang.NoClassDefFoundError: com/project_A_package/Project_A_Class
    com.project_B_package.Project_B_Class.startExternal(Project_B_Class.java:7)
    org.apache.jsp.project_B_jsp._jspService(project_B_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



root cause 
java.lang.ClassNotFoundException: com.project_A_package.Project_A_Class
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    com.project_B_package.Project_B_Class.startExternal(Project_B_Class.java:7)
    org.apache.jsp.project_B_jsp._jspService(project_B_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

需要做些什么才能解决此错误? 或者可能需要在项目A中进行调整才能在项目B中调用?

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

尝试将引用的项目A导出为Jar。 完成后,将A Jar以及A使用的所有其他Jar添加到您的webapp B的构建路径和B的部署程序集中。

希望这对你有用,而且答案还不算太晚!