JSP

 1. class TestBean

 

package ch08;

public class TestBean {

	private String id;
	private String pwd;
	private String name;
	
	
	public TestBean() {
	
	}

	public TestBean(String id, String pwd, String name) {
		super();
		this.id = id;
		this.pwd = pwd;
		this.name = name;
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		return "TestBean [id=" + id + ", pwd=" + pwd + ", name=" + name + "]";
	}
	
	
	
}

 

beanTestForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>

<form method="post" action="<%= request.getContextPath() %>/ch08/beanTestPro.jsp">
아이디 <input name="id" ><br>
비번 <input name="pwd"><br>
이름 <input name="name"><br>

<input type="submit" value="확인">

</form>



</body>
</html>

 

=>

 

아이디 
비번 
이름 

 

 

 

 

beanTestPro.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>

<!-- bean 의 변수값 읽기
 getProperty name="bean 의 id" property="변수명"

TestBean testBean=new TestBean(); 
testBean.setId(request.getParameter("id"));
testBean.setPwd(request.getParameter("pwd"));
testBean.setName(request.getParameter("name"));
-->
<%

	request.setCharacterEncoding("utf-8");
%>

<jsp:useBean id="testBean" class="ch08.TestBean">
 <jsp:setProperty name="testBean" property="*"/>
</jsp:useBean>

<%
	//out.println("아이디 : " + dto.getId());
%>


아이디 : <jsp:getProperty property="id" name="testBean"/>
<br>
비번 : <jsp:getProperty property="pwd" name="testBean"/>
<br>
이름 : <jsp:getProperty property="name" name="testBean"/>
<br>


</body>
</html>

 

=>

 

아이디 : braverokmc 
비번 : 1111 
이름 : 홍길동 

 

 

 

 

 

 

 

 

 

2. class RegisterBean

package ch08;

import java.sql.Timestamp;

public class RegisterBean {

	private String idt;
	private String psswd;
	private String name;
	private Timestamp reg_date;
	
	
	public String getIdt() {
		return idt;
	}
	public void setIdt(String idt) {
		this.idt = idt;
	}
	public String getPsswd() {
		return psswd;
	}
	public void setPsswd(String psswd) {
		this.psswd = psswd;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Timestamp getReg_date() {
		return reg_date;
	}
	public void setReg_date(Timestamp reg_date) {
		this.reg_date = reg_date;
	}
	
	@Override
	public String toString() {
		return "RegisterBean [idt=" + idt + ", psswd=" + psswd + ", name=" + name + ", reg_date=" + reg_date + "]";
	}
	
	
	
	
}






 

 

 

RegisterForm.jsp

 

<%@page import="java.sql.Timestamp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>


<form method="post" action="<%= request.getContextPath() %>/ch08/registerPro.jsp">

 <table>
	<tr>
	 <td>아이디</td>
	 <td><input name="idt"></td>
	</tr>
	
	<tr>
	 <td>비밀번호</td>
	 <td><input type="password" name="psswd" ></td>
	</tr>
	
	<tr>
	 <td>이름</td>
	 <td><input name="name" ></td>
	</tr>
	
	<input type="text" name="reg_date" value="<%= new Timestamp(System.currentTimeMillis() ) %>" >
	
	<tr>
	 <td align="center" colspan="2">
	  <input type="submit" value="확인">
	 </td>
	</tr>
 </table>




</form>


</body>
</html>

 

아이디
비밀번호
이름

 

 

 

 

 

registerPro.jsp

<%@page import="java.sql.Timestamp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>

</head>
<body>

<%
request.setCharacterEncoding("utf-8");
%>


<!-- registerPro.jsp -->
<!-- 폼에서 입력한 값들이 RegisterBean 객체에 입력됨 -->
<jsp:useBean id="registerBean" class="ch08.RegisterBean">
 <%-- <jsp:setProperty name="registerBean" property="*" /> --%>
 
  <jsp:setProperty name="registerBean"  property="idt"/>
  <jsp:setProperty name="registerBean"  property="psswd"/>
  <jsp:setProperty name="registerBean"  property="name"/>
</jsp:useBean>

<%
//System.currrentTimeMillis() 시스템의 현재 시각

//registerBean.setReg_date(new Timestamp(System.currentTimeMillis()));

 String time =request.getParameter("reg_date");

%>

아이디  : 
<jsp:getProperty property="idt" name="registerBean"/>
<br>
비번 :
<jsp:getProperty property="psswd" name="registerBean"/>
<br>
이름 :
<jsp:getProperty property="name" name="registerBean"/>
<br>
가입일자 :
<%= time %>



</body>
</html>


 

 

아이디 : braverokmc 
비번 : 1111 
이름 : 이순신 
가입일자 : 2017-05-22 14:07:33.401

 

 

 

 

 

 

 

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

자아(自我)를 부인하는 사람에게만 진리의 가르침이 보인다. -탈무드

댓글 ( 4)

댓글 남기기

작성