[MVC 3-6] EL - List

์ž„์Šนํ˜„ยท2023๋…„ 1์›” 25์ผ
0

MVC

๋ชฉ๋ก ๋ณด๊ธฐ
8/27

๐Ÿ“ƒStudent.java

package xyz.itwill.el;
//
public class Student {
	private int num;
	private String name;
	//
	public Student() {
		// TODO Auto-generated constructor stub
	}
	public Student(int num, String name) {
		super();
		this.num = num;
		this.name = name;
	}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
}

๐Ÿ“ƒstudent_list.jsp

<%@page import="java.util.ArrayList"%>
<%@page import="xyz.itwill.el.Student"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	List<Student> studentList=new ArrayList<Student>();
	studentList.add(new Student(1000, "ํ™๊ธธ๋™"));
	studentList.add(new Student(2000, "์ž„๊บฝ์ •"));
	studentList.add(new Student(3000, "์ „์šฐ์น˜"));
	studentList.add(new Student(4000, "์ผ์ง€๋งค"));
	studentList.add(new Student(5000, "์žฅ๊ธธ์‚ฐ"));
	//
	request.setAttribute("studentList", studentList);
	//
	request.getRequestDispatcher("student_list_el.jsp").forward(request, response);
%>

๐Ÿ“ƒstudent_list_el.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>MVC</title>
</head>
<body>
	<h1>EL - List</h1>
	<hr>
	<%-- EL ํ‘œํ˜„์‹์— . ์—ฐ์‚ฐ์ž๋กœ ์ฒจ์ž๋ฅผ ํ‘œํ˜„ํ•˜๋ฉด ELException ๋ฐœ์ƒ --%>
	<%-- <p>ํ•™๋ฒˆ = ${studentList.0.num }, ์ด๋ฆ„ = ${studentList.0.name }</p> --%>
	<%-- <p>ํ•™๋ฒˆ = ${studentList[0]["num"] }, ์ด๋ฆ„ = ${studentList[0]["name"] }</p> --%>
	<p>ํ•™๋ฒˆ = ${studentList[0].num }, ์ด๋ฆ„ = ${studentList[0].name }</p>
	<p>ํ•™๋ฒˆ = ${studentList[1].num }, ์ด๋ฆ„ = ${studentList[1].name }</p>
	<p>ํ•™๋ฒˆ = ${studentList[2].num }, ์ด๋ฆ„ = ${studentList[2].name }</p>
	<p>ํ•™๋ฒˆ = ${studentList[3].num }, ์ด๋ฆ„ = ${studentList[3].name }</p>
	<p>ํ•™๋ฒˆ = ${studentList[4].num }, ์ด๋ฆ„ = ${studentList[4].name }</p>
</body>
</html>

0๊ฐœ์˜ ๋Œ“๊ธ€