0

当我在网络服务器上有我的 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。先感谢您。

4

1 回答 1

0

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

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

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

于 2012-04-06T02:49:38.167 回答