【问题标题】:JSP imported class implementation not resloving typeJSP导入类实现不解析类型
【发布时间】:2012-04-06 02:47:31
【问题描述】:

当我在网络服务器上有我的 jsp 文件时,我遇到了一个异常,它显示以下内容:

    type Exception report

    message 

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception 

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

    An error occurred at line: 6 in the generated java file
    Only a type can be imported. edu.byu.isys413.data.Customer resolves to a package

    An error occurred at line: 124 in the jsp file: /account.jsp
    Customer cannot be resolved to a type
    121:                                         <tr valign=top>
    122:                                             <td height=19></td>
    123:                                             <% if (session.getAttribute("customer") != null) {
    124:                                                     Customer c = (Customer) session.getAttribute("customer");%>
    125:                                             <td align="center"><%="Welcome " +      c.getFirstName() + "!"%></td>
    126:                                             <% }%>
    127:                                             <td height=19></td>


    An error occurred at line: 124 in the jsp file: /account.jsp
    Customer cannot be resolved to a type
    121:                                         <tr valign=top>
    122:                                             <td height=19></td>
    123:                                             <% if (session.getAttribute("customer") != null) {
    124:                                                     Customer c = (Customer) session.getAttribute("customer");%>
    125:                                             <td align="center"><%="Welcome " + c.getFirstName() + "!"%></td>
    126:                                             <% }%>
    127:                                             <td height=19></td>


    Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

jsp页面看起来像

     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01             Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
         <%@ page import="edu.Customer" %>
 <% if (session.getAttribute("customer") != null) {
                                                Customer c = (Customer)    session.getAttribute("customer");%>
 <td align="center"><%="Welcome " + c.getFirstName() + "!"%></td>
                                        <% }%>

我知道很多人在这里发布了同样的问题,但我肯定 Customer.java 在 /WEB-INF/classes/edu/Customer.java 下。那么这里还有其他配置问题吗?我正在使用连接到 tomcat 的 IIS。我可以访问该文件,但我无法编译 JSP。 提前谢谢你。

【问题讨论】:

    标签: java jsp tomcat noclassdeffounderror


    【解决方案1】:

    我确定 Customer.java 在 /WEB-INF/classes/edu/Customer.java 下。

    您需要已编译的类文件而不是原始 Java 源文件。所以,你必须有一个/WEB-INF/classes/edu/Customer.class

    您可以使用javac 将Java 源文件编译为类文件。或者,当您已经很好地掌握了手动构建/编译 Java 项目并很好地理解了“类路径”现象时,可以考虑使用 Eclipse、IntelliJ 或 Netbeans 等 IDE。然后 IDE 会自动为您完成这一切。

    【讨论】:

    • 感谢您的评论。我尝试在 cmd 中运行 javac 命令,即使在我设置了 javac.exe 的路径后,它也无法识别 javac。你碰巧知道问题出在哪里吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-11
    • 2013-07-17
    • 2014-10-01
    • 2020-09-13
    • 1970-01-01
    相关资源
    最近更新 更多