jsp:useBean 형식
<jsp:useBean class="A" id="obj" scope="page"/>
- 클래스 객체생성 (영역:page, request, session, application)
start.jsp |
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <%--start.jsp --%> <body> <h3>나 스타트</h3> <a href="forward_test.jsp">forward_test.jsp로 이동</a> </body> </html> |
forward_test.jsp |
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <jsp:useBean class="j0523.Person" id="p" scope="application"></jsp:useBean> <%--j0523.Person p = new j0523.Person(); --%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <%--foward_test.jsp --%> <% String str = "너무쉽다"; request.setAttribute("k", str);//저장:setAttribute(String 속성명(key), Object 속성값(value)); p.setName("홍길동"); p.setAge(13); p.setJob("학생"); %> <body> <h3>forward테스트</h3> <jsp:forward page="end.jsp"/> </body> </html> |
end.jsp |
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <jsp:useBean class="j0523.Person" id="p" scope="application"></jsp:useBean> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <%--end.jsp --%> <body> <% out.print("이름:"+p.getName()+"<br>"); out.print("나이:"+p.getAge()+"<br>"); out.print("직업:"+p.getJob()+"<br>"); %> <h3>나는 종착페이지</h3> <% String st = (String)request.getAttribute("k"); //저장 %> STR=<%=st%> </body> </html> |
Person.java |
package j0523;
public class Person { private String name; private int age; private String job; public Person() { System.out.println("기본생성자"); }
public Person(String name, int age, String job) { super(); this.name = name; this.age = age; this.job = job; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public String getJob() { return job; }
public void setJob(String job) { this.job = job; } } |
page |

|
request |


|
session |


브라우저 재시작 후에 end.jsp 실행 시 이름, 나이, 직업이 null,0,null |