자바 중급 (JAVA-Web) 강좌 자료] Java Bean Example
자바 중급 (JAVA-Web) 강좌 자료] Java Bean Example

실무개발자를위한 실무교육 전문교육센터학원
www.oraclejava.co.kr에 오시면 보다 다양한 강좌를 보실 수 있습니다.
Java Bean Example
•/** 이 빈은 문자열을 뒤집거나 철자검사등을 한다.(SpellCheck.java) */
•public class SpellCheck {
• private String word;
• public SpellCheck() {}
• // 문자열을 뒤집는 메소드
• public String reverse() {
• return (new StringBuffer(word).reverse()).toString();
• }
• //철자검사 : 그냥 true를 넘기자
• public boolean check() { return true; }
• //word 속성에 대한 접근 메소드
• public String getWord() {
• return word;
• }
• //word 속성의 값을 설정
• public void setWord(String myWord) {
• word = myWord;
• }
•}
•<!– SpellCheck.html à
•<html>
•<head>
•<title> SpellCheck </title>
•</head>
•<body>
•<form action=/jsp/SpellCheck.jsp method=post>
•Enter word : <input type=text name=word>
•<select name=mode>
• <option value=1 selected>Reverse</option>
• <option value=2 >SpellCheck</option>
•</select>
•<input type=submit value=submit>
•</body>
•</html>
•<!– SpellCheck.jsp à
•<jsp:useBean id="help" scope="request" class="SpellCheck" />
•<jsp:setProperty name="help" property="*" />
•<html>
•<body>
•you enter the input , <b>
•<jsp:getProperty name="help" property="word" /> </b><br>
•The processed output is : <br>
•<%= Integer.parseInt(request.getParameter("mode")) == 1 ? help.reverse() : "“
•+help.check() %>
•</body>
•</html>