HTTP 状态 500:org.apache.jasper.JasperException:无法为 JSP 编译类
Posted
技术标签:
【中文标题】HTTP 状态 500:org.apache.jasper.JasperException:无法为 JSP 编译类【英文标题】:HTTP status 500: org.apache.jasper.JasperException: Unable to compile class for JSP 【发布时间】:2011-10-18 03:50:12 【问题描述】:我收到以下错误:
«HTTP Status 500 - 服务器遇到内部错误 () 导致无法完成此请求»,如下所示。我真的不知道为什么这个类不能解决。任何人都可以帮我解决错误吗?谢谢。:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 41 in the jsp file: /supprimer.jsp
List cannot be resolved to a type
38: </TR>
39: <%
40:
41: List <String> list = new ArrayList<String>(com.prog.GestionLivres.LivresDisponibles());
42:
43: int id = 0;
44: String box = null;
An error occurred at line: 41 in the jsp file: /supprimer.jsp
ArrayList cannot be resolved to a type
38: </TR>
39: <%
40:
41: List <String> list = new ArrayList<String>(com.prog.GestionLivres.LivresDisponibles());
42:
43: int id = 0;
44: String box = null;
An error occurred at line: 45 in the jsp file: /supprimer.jsp
Iterator cannot be resolved to a type
42:
43: int id = 0;
44: String box = null;
45: Iterator<String> it = list.iterator();
46:
47: while (it.hasNext())
48:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
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:644)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.21 logs.
<%@page import="com.prog.GestionLivres"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%-- <%@ page errorPage="erreur.jsp" %> --%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.Enumeration" %>
<HTML>
<HEAD>
<title>Supprimer</title>
<link rel="stylesheet" href="style.css" type="text/css">
</HEAD>
<BODY>
<%
Enumeration names = request.getParameterNames();
while (names.hasMoreElements())
String name = (String) names.nextElement();
StringBuffer sb = new StringBuffer(name);
sb.deleteCharAt(0);
com.prog.GestionLivres.Supprimer(sb.toString());
%>
<BR>
<DIV class="navigator">
<A href="ajouter.jsp">Ajouter</a>
<A id="currenttab" href="supprimer.jsp">Supprimer</A>
</DIV>
<BR> <BR> <BR>
<FORM action="supprimer.jsp" method="post">
<TABLE>
<TR>
<TH>Auteur</TH>
<TH>Titre</TH>
<TH>Année</TH>
<TH>Remarques</TH>
</TR>
<%
List <String> list = new ArrayList<String>(com.prog.GestionLivres.LivresDisponibles());
int id = 0;
String box = null;
Iterator<String> it = list.iterator();
while (it.hasNext())
id = Integer.parseInt(it.next());
out.print("<TR>");
for (int i = 0; i < 4; i++)
out.print("<TD>");
out.print(it.next());
out.print("</TD>");
out.print("<TD>");
box = "<INPUT name=r" + id + " type=’checkbox’>";
out.print(box);
out.print("</TD>");
out.print("</TR>");
%>
</TABLE>
<BR>
<INPUT type="submit" value="Supprimer">
</FORM>
</BODY>
</HTML>
package com.prog;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GestionLivres
static final String url = "jdbc:mysql://localhost:3306/bibliotheques";
public static void Insert(String auteur, String titre, int annee, String remarques)
try
String insert = "INSERT INTO livres(auteur, titre, annee, remarques)" + "VALUES (?, ?, ?, ?)";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, "root", "");
PreparedStatement ps = conn.prepareStatement(insert);
ps.setString(1, auteur);
ps.setString(2, titre);
ps.setInt(3, annee);
ps.setString(4, remarques);
ps.executeUpdate();
conn.close();
catch (Exception ex)
Logger.getLogger(GestionLivres.class.getName()).log(Level.SEVERE, null, ex);
public static List<String> LivresDisponibles()
List <String> list = new ArrayList<String>();
try
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, "root", "");
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM livres");
while(result.next())
list.add(result.getString("id"));
list.add(result.getString("auteur"));
list.add(result.getString("titre"));
//list.add(result.getInt("annee"));
list.add(result.getString("remarques"));
conn.close();
catch (Exception ex)
Logger.getLogger(GestionLivres.class.getName()).log(Level.SEVERE, null, ex);
return list;
public static void Supprimer(String id)
try
String supprimerEnregistrement = "DELETE from livres WHERE id = ?";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url, "root", "");
PreparedStatement ps = conn.prepareStatement(supprimerEnregistrement);
ps.setString(1, id);
ps.executeUpdate();
conn.close();
catch (Exception ex)
Logger.getLogger(GestionLivres.class.getName()).log(Level.SEVERE, null, ex);
【问题讨论】:
【参考方案1】:您需要在您的 JSP 中导入 java.util.List
和它抱怨的其他类,如:
<%@ page import="java.util.List,java.util.ArrayList,java.util.Iterator"%>
这只是为了让它编译。 IMO 不推荐这种设计,所有逻辑都应该在控制器中,您应该只将简单的 bean (POJO) 发送到视图层进行渲染。
【讨论】:
以上是关于HTTP 状态 500:org.apache.jasper.JasperException:无法为 JSP 编译类的主要内容,如果未能解决你的问题,请参考以下文章
验证 HTTP 200 和 500 状态码的 Alamofire 响应