ex. JSP 빈즈 프로그래밍

Posted 2008/11/06 14:17, Filed under: 학과수업들/JSP
* WEB-INF 폴더 아래 classes에는 클래스파일, src에는 자바소스 파일
ex) login.LoginBean => classes/login/LoginBean.class

login_form.html

<html>
<head>
<title> JSP Bean example </title>
</head>

<body bgcolor="#FFFFFF">
<center>
<h2>로그인 예제</h2>
<hr>

<form method="post" action="login.jsp" name="form1">
	<table width="250" border="1" align="center" cellspacing="0" cellpadding="5">
	<tr>
	<td colspan="2" align="center">로그인</td>
	</tr>
	<tr>
	<td>아이디</td>
	<td><input type="text" name="userid" size="10"></td>
	</tr>
	<tr>
	<td>패스워드</td>
	<td><input type="password" name="passwd" size="10"></td>
	</tr>
	<tr>
	<td colspan="2" align="center">
	<input type="submit" name="submit" value="로그인"</td>
	</tr>
	</table>
</form>

</center>
</body>
</html>

login.jsp

<%@ page contentType="text/html; charset=euc-kr" %>
<jsp:useBean id="login" class="login.LoginBean" scope="page" />
<jsp:setProperty name="login" property="*" />

<html>
<head><title></title></head>
<body>
<center>
<h2>로그인 예제</h2>
<hr>

<%
	if(!login.checkUser()) {
		out.println("로그인 실패");
	}
	else {
		out.println("로그인 성공");
	}
%>

<hr>
사용자 아이디 : <jsp:getProperty name="login" property="userid" /><br>
사용자 패스워드 : <jsp:getProperty name="login" property="passwd" />

</center>
</body>
</html>

LoginBean.java

// 패키지 선언
package login;

// 클래스 선언
public class LoginBean {

	// 멤버 변수 선언
	private String userid;
	private String passwd;

	final String _userid = "myuser";
	final String _passwd = "1234";

	public boolean checkUser() {
		if(userid.equals(_userid)&&passwd.equals(_passwd)) {
			return true;
		}
		else
			return false;
	}

	public void setUserid(String userid){
		this.userid = userid;
	}

	public void setPasswd(String passwd){
		this.passwd = passwd;
	}

	public String getUserid(){
		return userid;
	}

	public String getPasswd(){
		return passwd;
	}
}

2008/11/06 14:17 2008/11/06 14:17

Trackback URL : http://mysilpir.net/trackback/333

Leave a comment

« Previous : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : ... 270 : Next »

블로그 이미지

일상의 이야기를 나누는 공간입니다.

- 실피

Calendar

    «   2009/01   »
            1 2 3
    4 5 6 7 8 9 10
    11 12 13 14 15 16 17
    18 19 20 21 22 23 24
    25 26 27 28 29 30 31

Total 157607 hit (Today 52, Yesterday 185)

Admin Write Post