package web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class demo3 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<student> students=new ArrayList<student>();
student student1=new student("zhangsan","nan",9);
student student2=new student("lisi","nan",10);
students.add(student1);
students.add(student2);
//2.存储到request中
request.setAttribute("student",students);
//转发到 index中
request.getRequestDispatcher("/index.jsp").forward(request,response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request,response);
}
}
<%--
Created by IntelliJ IDEA.
User: 86159
Date: 2024/4/13
Time: 15:07
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
${student}
${3+2}
</body>
</html>
运行结果如下: