Contents

Develop
2013.04.23 16:22

OGNL(Object Graph Navigation Language)

조회 수 15777 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
[07-D10] OGNL(Object Graph Navigation Language)

[01] OGNL(Object Graph Navigation Language)
     - http://www.ognl.org/
     - %{ ... }안에 접근 문자열을 지정합니다. 반면에 EL은 ${ ... }로 시작합니다.
     - 객체 접근을 정규 표현식을 이용한 문자열의 변경처럼
       객체에 접근 할 수 있는 간결한 방법을 제공합니다.


1. struts2에서 OGNL을 이용하여 application운용과 관련된 servlet 자원에 접근하기위한 저장소의 구조

컨텍스트 맵 ---+-- application
               |
               +-- session 
               |
               +-- value stack(root 오브젝트, Action이 가지고 있는 멤버 변수 값)
               |   s:property 태그, EL과 같은 방법으로 접근(request 객체 내부)
               |
               +-- request 
               |
               +-- parameters
               |
               +-- atrr(page, request, session, application 영역 검색)


2. Action의 멤버 변수에 접근
   EL             : ${name}
   Struts2 XML TAG: <s:property value="name" />
   Scriptlet      : String name = (String)request.getAttribute("name") 

   최종적으로 public String getName(){ } 호출


3. Action의 public List getListString() 호출하여 요소 출력
   - 문자열 출력의 경우

    <s:iterator value="listString">
        <li><s:property /></li>
    </s:iterator>


4. Action안에 저장된 객체의 출력

<s:label>제품 이름: </s:label>
<!-- 
public Product getProduct() : DTO 추출
public String getName()     : DTO안의 멤버 변수(Attribute) 추출
-->
<s:property value="product.name" />


5. Action에 저장된 객체 목록의 출력시 env(개발자가 변경 가능) 환경 객체의 사용
   env는 개발자가 변경 가능

    <s:iterator value="listProduct" status="env">
        <tr bgcolor='<s:if test="#env.odd == true">lightgrey</s:if>'>
            <td><s:property value="name" /></td>
            <td><s:property value="modelNo" /></td>
        </tr>
    </s:iterator>


6. session 객체에서의 null 검사
   - session과 같은 root오브젝트가 아닌 자원의 접근하려면
     변수명앞에 '#'을 붙입니다.

   - session 객체에 저장된 'name'키로 등록된 객체를 가져옴
    <s:property value="#session.name" /> 
    또는
    <s:property value="#session['name']"/>

   - session 객체의 조건 비교
    <s:if test="%{#session.user != null}">
        <span class="headerMenu">
            <a href="<%=root %>/login/logout.action">로그아웃</a> | 
        </span>
    </s:if>
    <s:else>
        <span class="headerMenu">
            <a href="<%=root %>/login/loginForm.action">로그인</a> | 
        </span>
    </s:else>


7. session 객체에 저장된 DTO 객체의 변수 접근

(로그인 id: <s:property value="#session.user.id"/>)
(로그인 passwd: <s:property value="#session.user.passwd"/>)
(로그인 grade: <s:property value="#session.user.grade"/>)


8. request객체의 접근

#parameters['id'] == request.getParameter("id")
#request['id']    == request.getAttribute("id")
#session['id']    == session.getAttribute("id")


9. 문자열 비교 

<s:if test="%{#session.user.grade == 'AA'}">
    <a href="<%=root %>/login/logout.action">관리자 로그아웃</a> | 
</s:if>
<s:else>
    <a href="<%=root %>/admin_login_form.jsp">관리자 로그인</a> |
</s:else>


10. boolean의 비교

<s:if test="%{(#session.user.grade).startsWith('A') == true}">
    <a href="<%=root %>/login/logout.action">관리자 로그아웃</a> | 
</s:if>
<s:else>
    <a href="<%=root %>/admin_login_form.jsp">관리자 로그인</a> |
</s:else>


11. 수치 비교
    <td align="center"  bgcolor='<s:if test="%{(cnt-xcnt) < 0}">yellow</s:if>'>${cnt-xcnt}</td>
    <td align="center"  bgcolor='<s:if test="%{(cnt-xcnt) lt 0}">yellow</s:if>'>${cnt-xcnt}</td>


12. 일반 HTML태그에서의 Action내 객체 접근

<input type="text" name="name" id="name" value="${dto.name}" />

아래와 동일

<s:textfield name="name" size="10" value="%{dto.name}" />


13.  Application Scope Attribute
    - 프로젝트 전체에서 사용가능한 전역 변수
    - 모든 사용자, 웹 페이지에서 동일하게 사용

<s:property value="%{#application.totalWebSiteCount}" />

아래와 동일

<% out.print(application.getAttribute("totalWebSiteCount") %>


14. Session Scope Attribute
    - 사용자별로 생성되는 session 변수 사용
    - 사용자가 로그아웃하면 session변수도 삭제 

<s:property value="%{#session.producrCnt}" />

아래와 동일

<% out.print(session.getAttribute("producrCnt") %>


15. Request Scope Attribute
<s:property value="%{#request.grade}" />
또는 
<s:property value="grade" />

아래와 동일

<% out.print(reqeuest.getAttribute("grade") %>


16. Request Parameter
    - HTML <FORM>태그에서 전송한 데이터

<s:property value="%{#parameters.address}" />
또는
<s:property value="address" />
Struts는 <FORM>태그의 값을 자동으로 저장

아래와 동일

<% out.print(reqeuest.getParameter("address") %>


17. Action Class에서 httpServletRequest , HttpServletResponse 접근

Action implements, ActionSupport extends 할 경우

아래처럼 기술
HttpServletRequest request = ServletActionContext.getRequest();
this.root = request.getContextPath();    


18. 각종 Map 출력(키, 값의구조일 경우)

<s:iterator value="mapData">
    ${key } 
    ${value } 
    <td align="right"> ${value.commaPrice}</td>
</s:iterator>


사용예)
  <s:iterator value="list" status="env">
      <s:set name="no" value="#env.index+1" />

    <input type="button" name="count" value="수정" 
            onclick="javascript:updateCheck(<s:property value="#no"/>, ${value.productno}, ${value.price}, ${value.baesong})" />
    </td>
    <td align="right"> ${value.price}</td>
    <td align="right"> ${value.total}</td>
    <td> 
<input type="button" name="delete" value="삭제" 
onclick="javascript:deleteCheck(${value.productno})" />


19. s:url 태그

<s:url id="urlID" namespace="/members2" action="read" >
    <!-- getId() 호출 -->
    <s:param name="id" value="id"/>
</s:url>

<s:a href="%{urlID}"> <!-- s:url 태그 참조 -->
    <s:property value="id" /> <!-- id 출력 -->
</s:a>


20. set 태그

<s:set name="personName" value="person.name"/>
Hello, <s:property value="#personName"/>. How are you?


21. Action class에서 저장된 문자열이 HTML 태그를 포함하는 경우
    - 태그를 내용으로 출력
      <s:property value="msg"/>

    - 태그가 처리되어 결과만 출력
      <s:property value="msg" escape="false" />


22. Action class execute()메소드 에서의 HttpServletRequest 객체 접근

        HttpServletRequest request = ServletActionContext.getRequest();
        System.out.println("request.getContextPath(): " + request.getContextPath());

[출처] OGNL(Object Graph Navigation Language)

?

  1. iOS 에서 쓸만한 오프라인 구글지도 찾기

    Date2014.01.06 CategoryEtc Byhooni Views16090
    Read More
  2. [doc] 웜 프레임워크 검증환경 구축(작성중..)

    Date2013.04.23 CategoryEtc Byhooni Views16057
    Read More
  3. 티스토리 테이블 html,css 구문

    Date2013.11.03 CategoryEtc Byhooni Views16046
    Read More
  4. 여기저기서 모은 VoIP(인터넷전화) 자료들~

    Date2013.04.23 CategoryEtc Byhooni Views16029
    Read More
  5. [owasp] 10대 웹어플리케이션 보안 취약

    Date2013.04.23 CategorySystem/OS Byhooni Views15992
    Read More
  6. [ppt] 웜 과제 진행사항(프레임워크 검증환경 구축) 보고

    Date2013.04.23 CategoryPPT Byhooni Views15931
    Read More
  7. 라우팅 경로 결정 영향 요소 ㅋㅋ

    Date2013.04.23 CategorySystem/OS Byhooni Views15929
    Read More
  8. [ios] APNS 클라이언트 구현 (pdf)

    Date2013.06.27 CategoryDevelop Byhooni Views15833
    Read More
  9. 영어의 12 시제 (The twelve tenses of English)

    Date2013.07.12 CategoryEtc Byhooni Views15793
    Read More
  10. OGNL(Object Graph Navigation Language)

    Date2013.04.23 CategoryDevelop Byhooni Views15777
    Read More
  11. [router] 설정과 기본 명령어들 모음

    Date2013.04.23 CategorySystem/OS Byhooni Views15749
    Read More
  12. [linux] 쉘스크립트 expr

    Date2014.03.11 CategorySystem/OS Byhooni Views15706
    Read More
Board Pagination Prev 1 ... 17 18 19 20 21 22 23 24 25 26 ... 98 Next
/ 98