#actiontag
seen from China

seen from United States

seen from United States
seen from Germany

seen from Türkiye

seen from Russia

seen from Singapore
seen from Finland
seen from Germany

seen from France
seen from Australia
seen from United States

seen from United States

seen from United States

seen from Romania

seen from United States
seen from Belgium

seen from Canada
seen from United States
seen from Malaysia
#actiontag

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
JSP setProperty, getProperty 예제
fileoutputstream을 이용한 setProperty, getProperty 예제
<%@ 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> <body> <form action="param1.jsp" method="get"> <%-- --%> ID : <input type="text" name="id"><br /> 이름 : <input type="text" name="name"><br /> 비밀번호 : <input type="password" name="pw"><br /> 이메일 : <input type="text" name="email"><br /> <input type="submit" value="전송"> </center> </form> </body> </html><%--param1.jsp--><%@page import="java.io.ObjectOutputStream"%> <%@page import="java.io.FileOutputStream"%> <%@page import="java.util.Date"%> <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <% request.setCharacterEncoding("utf-8"); %> <!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> <jsp:useBean id="user" class ="project.User"/> <%-- <jsp:setProperty property="id" name="user" param = "id"/> <jsp:setProperty property="name" name="user" param = "name"/> <jsp:setProperty property="pw" name="user" param = "pw"/> <jsp:setProperty property="email" name="user" param = "email"/> --%> <jsp:setProperty property="*" name="user" /> <jsp:setProperty property="regDate" name="user" value ="<%=new Date() %>"/> <% String path = "D:\\test.txt";//application.getRealPath("/day4/user_"+user.getId()); FileOutputStream fos = new FileOutputStream(path); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(user); oos.close(); %> <body> 회원가입 처리 완료<br/> 아이디:<jsp:getProperty property="id" name="user"/><br/> 이름:<jsp:getProperty property="name" name="user"/><br/> 가입일:<jsp:getProperty property="regDate" name="user"/><br/> 이메일:<jsp:getProperty property="email" name="user"/><br/></body> </html><!--login_form.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> <body> 관리자 로그인<br/> <form action="login.jsp" method = "post"> ID : <input type = "text" name = "id"><br/> Password : <input type = "password" name = "pw"><br/> <input type = "submit" value = "전송"> </form></body> </html><!--login.jsp--><%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import = "project.User" %> <%@ page import = "java.io.*" %> <!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> <body> <% String beanId = null; String beanPw = null; String id = request.getParameter("id"); String pw = request.getParameter("pw"); try{ String path = "D:\\test.txt";//application.getRealPath("/day4/user_"+id); FileInputStream fis = new FileInputStream(path); if(fis !=null){ ObjectInputStream ois = new ObjectInputStream(fis); User user = (User)ois.readObject(); beanId = user.getId(); System.out.println(beanId); beanPw = user.getPw(); ois.close(); } }catch(IOException e){ out.println("<script>alert(\"회원 DB 오류 발생\");history.back();</script>"); } if(beanId ==null|beanPw==null){ out.println("<script>alert(\"회원 정보가 없습니다\");history.back();</script>"); } if(id.equals(beanId)&&pw.equals(beanPw)){ session.setAttribute("userId", id); out.println("로그인에 성공했습니다"); }else if(id.equals(beanId)){ out.println("<script>alert(\"비밀번호불일치\");history.back();</script>"); }else{ out.println("<script>alert(\"아이디불일치\");history.back();</script>"); } %> </body> </html>
데이터를 객체 단위로 묶어서 처리
jsp 소스가 깔끔해짐
생성자, property, get, set으로 구성
useBean으로 사용되는 객체는 반드시 변수명과 똑같이 set/get메서드를 가지고 있어야 한다
자바빈 관련 액션 태그
<jsp:useBean id="..." class="..." scope="..."/>
자바빈 객체를 생성
id는 생성될 자바빈 객체의 이름
class 속성은 객체가 생성될 자바빈 클래스를 기술 (패키지명을 포함한 자바 클래스)
scope 속성은 자바빈 객체의 유효 범위로 자바빈 객체가 공유되는 범위를 지정한다. 생략시 default는 "page" ( page, request, session, application )
<jsp:setProperty name="..." property="..." value="..." />
생성된 자바빈 객체에 프로퍼티 값을 저장
property ="*" 를 주면 모든 프로퍼티 값이 세팅된다 form으로부터 넘어오는 파라미터의 이름과 개수가 프로퍼티의 이름과 개수와 일치해야 한다
<jsp:setProperty name="testBean" property="name" /> 액션 태그는 자바빈 클래스의 setName() 메소드와 자동 연동된다
폼으로부터 넘어온 파라미터 명과 자바빈의 프로퍼티가 일치하지 않는 경우 param 속성을 기술해야 한다
<jsp:getproperty name="..." property="..." />
생성된 자바빈 객체에서 저장된 프로퍼티 값을 가져옴.
자바빈 예제
User클래스 java code
package project; import java.util.Date; import java.io.Serializable; public class User implements Serializable { private String id; private String name; private String pw; private String email; private Date regDate; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPw() { return pw; } public void setPw(String pw) { this.pw = pw; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Date getRegDate() { return regDate; } public void setRegDate(Date regDate) { this.regDate = regDate; } }
useBean.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <jsp:useBean id = "user" class = "project.User" scope = "request"/> <!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> <body> <%= user.getName() %>(<%= user.getId() %>)회원님 등장.<br/> 이메일은 <%= user.getEmail() %>입니다.<br/> 가입 날짜는 <%= user.getRegDate() %>입니다. </body> </html>
setBean.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import = "java.util.Date" %> <!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> <body> <jsp:useBean id = "user" class ="project.User" scope = "request"/><%--객체 생성 --%> <% user.setId("jwkim"); user.setName("시비르"); user.setPw("1234"); user.setEmail("[email protected]"); user.setRegDate(new Date()); %> <jsp:forward page="useBean.jsp"></jsp:forward> </body> </html>
JSP forward action tag
액션 태그 <jsp:forward >
다른 페이지로 프로그램의 제어를 이동할 때 사용
출력 버퍼에 저장되어 있던 내용을 제거하고 forward 액션 태그가 지정하는 페이지의 출력결과가 버퍼에 들어감
forward 액션 태그의 page 속성은 이동할 페이지명을 기술하고 상대경로, 절대경로로 지정할 수 있다
forward 액션 태그에서 포워딩되는 페이지에 파라미터 값을 전달할 수 있다.
지정하는 페이지의 코드를 원래 페이지로 가져옴
forward 예제
<%@ 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> <body> <% String code = request.getParameter("code"); String viewPageURI = null; if (code.equals("1")){ viewPageURI = "/day3/1.jsp"; }else if(code.equals("2")){ viewPageURI = "/day3/2.jsp"; } %> <jsp:forward page="<%= viewPageURI %>"></jsp:forward> </body> </html>
포워딩할 페이지에 parameter 전달 예제
<%@ 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> <body> <% String value = request.getParameter("p1"); if(value == null) value = "NOPARAM"; %> <jsp:forward page="/day3/paramto.jsp"> <jsp:param name = "p2" value= "<%=value %>"/> </jsp:forward> </body> </html>
<!--paramto-->
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> p1 파라미터 :<%=request.getParameter("p1") %><br/> p2 파라미터 :<%=request.getParameter("p2") %> </body> </html>
request 객체의 속성을 이용한 전달
<%@page import="java.util.Calendar"%> <%@ 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> <body> <% Calendar cal = Calendar.getInstance(); request.setAttribute("cal", cal); request.setAttribute("name", "우르곳"); %> <jsp:forward page="/day3/recv_attr.jsp"></jsp:forward> </body> </html>
<!--recv_attr.jsp-->
</head> <body> <% Calendar cal = (Calendar)request.getAttribute("cal"); String name = (String)request.getAttribute("name"); %> <%= name %> 부활시간 <%= cal.get(Calendar.HOUR) %>시 <%= cal.get(Calendar.MINUTE) %>분 <%= cal.get(Calendar.SECOND) %>초입니다. </body> </html>
respon 객체를 이용한 클라이언트 측에서 포워딩 하는 예제
<%@page import="java.util.Random"%> <%@ 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> <body> <% Random random = new Random(); int number = random.nextInt(); String numberString = Integer.toString(number); //response.sendRedirect(request.getContextPath()+"/day3/res_rv.jsp?num="+numberString); %> <script type="text/javascript"> location.href = "<%= request.getContextPath() %>/day3/res_rv.jsp?num=<%=numberString%>"; </script> </body> </html>
<!--res_rv-->
</head> <body> 전달받은 정수:<%= request.getParameter("num") %> </body> </html>