javaBean
자바빈은 테이터를 표현하는 것을 목적으로 하는 자바 클래스이다.
아래 예시에서 Person은 JavaBean이다.
그래서 빈과 관련된 표준 액션(standard action을 사용할수 있다.
javaBean 선언하기
<jsp:useBean id="person" class="example.Person" scope="request">
</jsp:useBean>
<jsp:useBean>은 자바빈을 사용한다는 선언이다.
id 는 사용할 javaBean의 이름 이고,
class 는 javaBean에서 사용할 클래스명이다.
즉, 여기서는 person이라고 javaBean을 선언해주고 person이라는 javaBean은 example.Person클래스를 사용한다는 것이다.
javaBean 사용 예제
From.html
<%@ 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="result.jsp" method="post">
name : <input type="text" name="username1" size=20>
<br>
ID# : <input type="text" name="nickname1" size=20>
<br>
<input type="submit">
</form>
</body>
</html>
Person.java
package example;
public abstract class Person {
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
private String username;
private String nickname;
}
result.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>
<jsp:useBean id="person" class="example.Person">
<jsp:setProperty name="person" property="username" value="<%=request.getParameter("username1") %>"/>
<jsp:setProperty name="person" property="nickname" param="nickname1"/>
</jsp:useBean>
Person(username) : <jsp:getProperty name="person" property="username" />
<br>
Person(nickname) : <jsp:getProperty name="person" property="nickname" />
<br>
</body>
</html>
"" 오류날시에 해결법
위에 result.jsp 에서
value="<%=request.getParameter("username1") %>"
이부분이 오류날 때 해결하는법.
-Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false
을 server에서 Open launch configuration 으로 들어가서, Arguments의 VM 부분에 넣어줄것.
단, 엔터치지 말것!'Programming' 카테고리의 다른 글
JSP에서 DB 접속 절차. (0) | 2009.08.13 |
---|---|
프로퍼티가 String,기본형이 아닌것 출력하는 법. (0) | 2009.08.12 |
The Three Scopes : Context, Request, and Session (0) | 2009.08.11 |
속성(파라미터) (0) | 2009.08.11 |