Java jsp文件中的Dispaly servlet arraylist不工作

Java jsp文件中的Dispaly servlet arraylist不工作,java,jsp,servlets,Java,Jsp,Servlets,我不明白为什么我的jsp页面不会显示我在servlet中创建并添加到会话中的列表。 任何帮助都将不胜感激。我已经看了很多答案,但我找不到一个可以解决这个问题的答案 我得到的输出是 艺术家资料摘要 姓Fname国籍出生 因此,显示的是表格标题,而不是实际值 艺术家班 public class Artist { private String firstname; private String surname; private String nationality;

我不明白为什么我的jsp页面不会显示我在servlet中创建并添加到会话中的列表。 任何帮助都将不胜感激。我已经看了很多答案,但我找不到一个可以解决这个问题的答案

我得到的输出是

艺术家资料摘要

姓Fname国籍出生 因此,显示的是表格标题,而不是实际值

艺术家班

public class Artist {
     private String firstname;
    private String surname;
    private String nationality;
    private int birthyear;



    public Artist(String F, String S, String N, int I){
        this.firstname=F;
        this.surname=S;
        this.nationality=N;
        this.birthyear=I;

    }

    public String getFirstName(){
        return firstname;
    }



        public String getSurname(){
        return surname;
    }
          public String getNationality(){
        return nationality;
    }

        public int getBirth(){
        return birthyear;
        }  

}


Servlet

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author User
 */
@WebServlet(urlPatterns = {"/NewServlet"})
public class NewServlet extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {


            Artist A1 = new Artist("smith", "john", "american", 1999);
            Artist A2 = new Artist("pan", "peter", "canadian", 1956);

            List<Artist> list = new ArrayList<Artist>();
            list.add(A1);
            list.add(A2);

              HttpSession session = request.getSession(); 
        session.setAttribute("info", list);

        RequestDispatcher dispatcher = request.getRequestDispatcher("/newjsp.jsp");
        dispatcher.forward(request,response);

            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet NewServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}

JSP文件

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head></head>
      <body>
        <h1>Summary of artist information</h1>
        <table>
            <thead>
            <tr>
                <th>Surname</th>
                <th>Fname</th>
                <th>nationality</th>
                <th>birth</th>


            </thead>
           <c:forEach items="${art}" var="artist">
                <tr>
                    <td>${artist.Surname}</td>
                    <td>${artist.Firstname}</td>
                    <td>${artist.Nationality}</td>
                    <td>${artist.BirthYear}</td>
                </tr>
                </c:forEach>



        </table>
    </body>
</html>

艺术家资料摘要
姓
Fname
国籍
出生
${艺术家姓氏}
${artist.Firstname}
${艺术家国籍}
${艺术家生日}

您正在使用name
info
在会话变量中设置手动创建的艺术家列表,如下所示

session.setAttribute("info", list);
如果要将此数据显示到jsp上,则需要在
c:forEach
循环中使用名为
info
的相同变量,如下所示

<c:forEach items="${info}" var="artist">
                <tr>
                    <td>${artist.surname}</td>
                    <td>${artist.firstname}</td>
                    <td>${artist.nationality}</td>
                    <td>${artist.birthYear}</td>
                </tr>
  </c:forEach>

${艺术家姓氏}
${artist.firstname}
${艺术家国籍}
${艺术家生日}

还要密切注意上面每个JSTL使用的属性名称、姓氏、名字等。

嘿,伙计,感谢你花时间看这个,我更正了错误,我将它改为你列出的ie items=“${info}”,我更正了变量名称,但我仍然得到相同的输出。你知道为什么吗?