我已经做了相当多的研究,从我所看到的来看,我的一切都是正确的。我试图在我的 JSP 文件中调用 Java 类。每次我运行它时,我都会收到以下错误:
org.apache.jasper.JasperException:无法为 JSP 编译类: 在 jsp 文件中的第 25 行发生错误:/3680-HW4-Taylor-Jacob/HTML/main.jsp DateAssistant.formatDate 无法解析为类型 22:out.println("欢迎," + request.getParameter("usrname") + "!"); 23: 24: if (timezone.equalsIgnoreCase("United States")){ 25: out.write("您登录:“ + new DateAssistant.formatDate(gc, timezone) +”
"); 26: 27:} 28: out.write("浏览电影目录"); 堆栈跟踪: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468) org.apache.jasper.compiler.Compiler.compile(Compiler.java:378) org.apache.jasper.compiler.Compiler.compile(Compiler.java:353) org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) 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)
我将 Class 文件放在正确的位置(WEB-INF/classes/wu/andy/DateAssistant.class),并且从我所看到的内容中正确导入。这是我的 JSP 源代码:
<%@ page import="java.util.GregorianCalendar, wu.andy.*" %>
<%
String interest = request.getParameter("interest");
String password = request.getParameter("password");
GregorianCalendar gc = new GregorianCalendar();
int tz = 0;
String timezone = request.getParameter("country");
if(password.equals("JTaylor")){
if(interest.equals("music")){
response.sendRedirect("music.html");
}
else if(interest.equals("games")){
response.sendRedirect("games.html");
}
else if(interest.equals("movies")){
out.write("<html>");
out.write("<head/>");
out.write("<body>");
out.write("<h1 style='color:green'>Movies Galore :: User Main Page</h1>");
out.println("Welcome, " + request.getParameter("usrname") + "!");
if (timezone.equalsIgnoreCase("United States")){
out.write("<p>You logged in on: " + new DateAssistant.formatDate(gc, timezone) + "</p><br/><br/>");
}
out.write("<a href='movies.html'>Browse Movies Catalog</a>");
}
} else{
response.sendRedirect("login.html");
}
%>
我知道我的代码不是“好的做法”,但这就是我的教授想要的。
任何帮助,将不胜感激!