package com.koit.vo; public class User { public String userid; public String username; public int age; public User(String userid, String username, int age) { super(); this.userid = userid; this.username = username; this.age = age; } }
<%@ page import="com.koit.vo.User"%>
-> 패키지명.클래스명
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="com.koit.vo.User"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <% // 객체배열 User[] arrUser = { new User("id1", "유저1", 20), new User("id2", "유저2", 30), new User("id3", "유저3", 40) }; //request 객체, setAttribute request.setAttribute("arrUser", arrUser); // forward 페이지 이동, attribute6.jsp> pageContext.forward("attribute6.jsp"); %> </body> </html>
</br>
<hr>
- attribute6.jsp 파일에서 객체배열 값 받아와서 출력하기
>```html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.koit.vo.User"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
User[] users = (User[])request.getAttribute("arrUser");
for(int i = 0; i < users.length; i++){
out.println(users[i].userid );
out.println(users[i].username );
out.println(users[i].age + "<br>");
}
%>
</body>
</html>