상세 컨텐츠

본문 제목

<jsp:include page=""/>태그

프로그래밍/JAVA

by 라제폰 2009. 1. 30. 17:47

본문

[a.jsp]
----------------------------------
<jsp:include page="b.jsp" />
a.jsp 입니다.
----------------------------------

[b.jsp]
----------------------------------
b.jsp 입니다.
----------------------------------

위와 같은 소스를 이용하여 WebSphere 3.5.x JSP 1.1 모드에서 수행하면 다음과 같은
에러를 만납니다.

"Invalid jsp:include tag"

왜일까요?

아래는 JSP 1.0 과 JSP 1.1 의 Specification 입니다.

JSP 1.0 Specification
    2.13.4 <jsp:include>
    A <jsp:include .../> element provides for the inclusion of static and dynamic
    resources in the same context as the current page. See TABLE 2-1 for a summary
    of include  facilities.
    The resource is specified using a relativeURLspec that is interpreted in the
    context of the Web server (i.e. it is mapped). See Section 2.5.2.
    An included page only has access to the JspWriter object and it cannot set
    headers. This precludes invoking methods like setCookie(). A request-time
    Exception will be raised if this constraint is not satisfied. The constraint
    is equivalent to the one imposed on the include() method of the RequestDispatcher
    class.
    Request processing resumes in the calling JSP, once the inclusion is completed.
    If the page output is buffered then the buffer is flushed prior to the
    inclusion 1.
    Examples
    <jsp:include page="/templates/copyright.html" flush="true"/>

    2.13.4.1 Syntax
    <jsp:include page=" urlSpec" flush="true"/>

    The valid attributes are:
    page: The URL is a relative urlSpec is as in Section 2.5.2.
        Accepts a request-time attribute value (which must evaluate to a String
        that is a relative URL specification).
    flush: Mandatory boolean attribute. If the value is "true", the buffer is
        flushed. A "false" value is not valid in JSP 1.0.


JSP 1.1 Specification
    2.13.4 <jsp:include>
    A <jsp:include .../> element provides for the inclusion of static and dynamic
    resources in the same context as the current page. See TABLE 2-1 for a summary
    of include facilities.
    The resource is specified using a relativeURLspec that is interpreted in the
    context of the Web server (i.e. it is mapped). See Section 2.5.2.
    An included page only has access to the JspWriter object and it cannot set
    headers. This precludes invoking methods like setCookie(). A request-time
    Exception will be raised if this constraint is not satisfied. The constraint
    is equivalent to the one imposed on the include() method of the
    RequestDispatcher class.
    A jsp:include action may have jsp:param subelements that can provide values
    for some parameters in the request to be used for the inclusion.
    Request processing resumes in the calling JSP page, once the inclusion is
    completed.
    If the page output is buffered then the buffer is flushed prior to the
    inclusion. See Section B.4 for an implementation note. See Section 5.4.5 for
    limitations on flushing when out is not the top-level JspWriter.
    Examples
    <jsp:include page="/templates/copyright.html"/>

    2.13.4.1 Syntax
    <jsp:include page=" urlSpec" flush="true"/>
    and
    <jsp:include page=" urlSpec" flush="true">
    { <jsp:param .... /> }*
    </jsp:include>

    The first syntax just does a request-time inclusion. In the second case, the
    values in the param subelements are used to augment the request for the
    purposes of the inclusion.
    The valid attributes are:
    page: The URL is a relative urlSpec is as in Section 2.5.2.
         Accepts a request-time attribute value (which must evaluate to a String
         that is a relative URL specification).
    flush: Mandatory boolean attribute. If the value is "true", the buffer is
         flushed. A "false" value is not valid in JSP 1.1.


정리하면, <jsp:include ..../> 를 사용할 때, flush="true" 옵션은 JSP 1.0, JSP 1.1
모두에서 Mandatory 라는 것입니다.

이제 소스를 다시 고쳐 보도록 하겠습니다.

[a.jsp]
----------------------------------
<jsp:include page="b.jsp" flush="true"/>
a.jsp 입니다.
----------------------------------
[b.jsp]
----------------------------------
b.jsp 입니다.
----------------------------------


잘 되는 군요....

결론: 반드시 flush="true" 를 주셔야 합니다. flush 는 JSP 1.0, JSP 1.1 모두에서
반드시 적어야 되며, boolean 값으로 false 를 지정할 순 없습니다.

그럼 왜 WebSphere 3.5.x JSP 1.0 에서는 flush="true" 를 주지 않아도 되었느냐라는
부분은 WebSphere 3.5.x JSP 1.0 컴파일러가 JSP 1.0 스펙을 준수하지 않았었다고
밖에 설명이 안되는 군요....

그리고, JSP 1.1 스펙에서 examples 를 보면 flush="true" 부분이 생략되어 있는데,
(제 생각엔) 상반되는 내용이군요. flush 옵션은 mandatory 라고 하면서 Examples 에는
생략해 두었네요. JSP 1.0 의 Examples 에는 flush 옵션이 분명히 들어가 있는데
말입니다. 
아니라면, JSP 스펙상의 설명이야 어떻든, flush 옵션은 어차피  "true" 값 밖에
아직 정의하지 않았으므로, 생략가능하도록 규정했을 수도 있는데, 이 경우라면
WebSphere 3.5.x JSP 1.1 컴파일러를 이 부분에 대해 제대로 구현하지 않았다고 설명할
수도 있겠습니다.

어쨌거나, flush="true" 를 넣어 주시죠....

PS: <jsp:include ...>  시에  <jsp:param .../> 옵션은 JSP 1.1 에서만 된다는 것을
주지하십시요.

------------------------------------------------------- 
  본 문서는 자유롭게 배포/복사 할 수 있으나 반드시
  이 문서의 저자에 대한 언급을 삭제하시면 안됩니다
================================================
  자바서비스넷 이원영
  E-mail: javaservice@hanmail.net
  PCS:011-898-7904
================================================

관련글 더보기