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>

















