JSP Action Tag

이기현·2020년 1월 9일
0

2020Camp

목록 보기
3/16

JSP에서 Java Code 등의 스크립트 언어를 쓰지않고 HTML 형태로 다른 페이지의 서블릿이나 자바빈 객체에 접근 가능할 수 있도록 태그를 이용해 구현된 기능

출처: https://kit2013.tistory.com/87 [정윤상이다.]

표준 액션 태그는 미리 정해진 기능들을 JSP 스펙에 명시함으로써 모든 컨테이너가 동일하게 구현하는 태그입니다. 모든 JSP 컨테이너에서 기본으로 제공하고 있어서 기본 액션 태그라고도 합니다. 표준 액션 태그는 특별한 선언 없이 "jsp"라는 접두어를 붙여 태그명만 명시하면 컨테이너가 인식해서 수행합니다.

  • 페이지 흐름 제어 액션 (forward / include Action)

  • 자바빈 사용 액션 (useBean Action)

  • 애플릿 사용 액션 (plugin Action)

1. jsp:forward action tag

forward action tag is used to forward the request to another resource it may be jsp, html or another resource

<jsp:forward page="printdate.jsp" /> 

2. jsp:include action tag

정적 include 와 동적 include

  1. 정적 include

jsp가 컴파일되기 전에 include한 파일(common.jsp)이 부모 페이지에 삽입되어 컴파일된다.

사용법 :

<%@include file="/inc/common.jsp" %> 

장점 : include 페이지에서 선언한 변수를 부모페이지에서 별도의 변수 선언없이 사용이 가능하다.
단점 : 부모 페이지에 include한 파일이 많을경우 inlucde 페이지에서 선언된 변수를 추적해야해 유지보수할때 귀찮다.

  1. 동적 include

사용자가 부모페이지 호출시 실행되어질 시점에 include한 파일이 삽입된다.

사용법 :

<jsp:include page="/inc/common.jsp" flush="true" />

장점 : 부모페이지와 include 페이지는 변수를 공유하지 않으므로 유지 보수시에 편하다.
단점 : 부모페이지에서 include한 파일에서 선언한 변수를 사용시 <jsp:param name="userName" value="<%=userName%>"/> 과 같이 부모페이지에서 지정해 주어야 한다.

자바빈(JavaBean)이란 ?

A JavaBean is a Java class that should follow the following conventions:

  • It should have a no-arg constructor.(매개변수 존재 X)
  • It should be Serializable.
  • It should provide methods to set and get the values of the properties, known as getter and setter methods.

JavaBean을 사용하는 이유는?

According to Java white paper, it is a reusable software component. A bean encapsulates many objects into one object so that we can access this object from multiple places. Moreover, it provides easy maintenance.

자바빈 사용법

Employee e=new Employee();//object is created  
e.setName("Arjun");//setting value to the object  
System.out.println(e.getName());  

jsp:useBean

javabean.PNG

jsp: setProperty

setProperty 액션태그는 자바빈 파일의 setter 메서드를 사용하기 위해, 즉 데이터의 값을 설정할 때 사용된다. 형식은 아래와 같다.

<jsp:setProperty name="빈 이름" property="필드명" value="" />
<jsp:setProperty name="빈 이름" property="*" />

지금까지 내가 이해하기로는, property는 POST 나 GET을 통해 넘어온 값들을 사용할 수 있는 것 같다.

jsp: getProperty

getProperty 액션태그는 자바빈 파일의 getter 메서드를 사용하기 위해, 즉 저장된 데이터의 값을 읽어올 때 사용된다. 형식은 아래와 같다.(참고로 getProperty 액션태그는 거의 사용하지 않는다.)

<jsp:getProperty name="빈이름" property="필드명" />
profile
실력을 쌓아가는 하루하루

0개의 댓글