当我在网络服务器上安装了我的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。 提前谢谢。
答案 0 :(得分:0)
我当然确定Customer.java位于/WEB-INF/classes/edu/Customer.java下。
您需要编译的类文件而不是原始Java源文件。因此,您必须拥有/WEB-INF/classes/edu/Customer.class
。
您可以使用javac
将Java源文件编译为类文件。或者,当您已经掌握了手动构建/编译Java项目以及对“类路径”现象的充分理解时,可以考虑使用Eclipse,IntelliJ或Netbeans等IDE。然后,IDE将自动为您完成所有操作。