HTTP 状态 500:org.apache.jasper.JasperException:无法编译 JSP 类

发布于 2024-12-10 20:45:49 字数 7631 浏览 0 评论 0原文

我收到以下错误:

“HTTP 状态 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);
        }
    }
}

I'm getting the following error:

«HTTP Status 500 -The server encountered an internal error () that prevented it from fulfilling this request» as it is shown as following. I really don't know why this class cannot be resolve. Anyone could help me to fix the error please? Thanks.:

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);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢蛋碎的人ぎ生 2024-12-17 20:45:49

您需要在 JSP 中导入 java.util.List 及其所抱怨的其他类,如:

<%@ page import="java.util.List,java.util. ArrayList,java.util.Iterator"%>

这只是为了编译它。 IMO 不推荐这种设计,所有逻辑都应该在控制器中,并且您应该只将简单的 bean (POJO) 发送到视图层进行渲染。

You need to import java.util.List and other classes its complaining about in your JSP, as in:

<%@ page import="java.util.List,java.util.ArrayList,java.util.Iterator"%>

Thats just to get it to compile. IMO this design is not recommended, all of the logic should be in the controller and you should only send simple beans (POJOs) to the view layer for rendering.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文