블로그 이미지
헤이장

Notice

Recent Post

Recent Comment

Recent Trackback

calendar

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
  • total
  • today
  • yesterday
2009. 7. 27. 20:38 Web/Jsp

EL 태그로 함수를 호출 하려면 어떻게 해야할까? 

1. 사용할 정적(static) 메서드를 만든다


GetPi.java


package elf;

public class GetPi {
    public static double getValue(Double plus) {
        return 3.14 + plus;
    }
}


 elf.tld

<?xml version="1.0" encoding="UTF-8"?>

<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
    <tlib-version>1.0</tlib-version>
    <short-name>elf</short-name>
    <uri>elfunction</uri>
    <function>
        <name>pi</name>
        <function-class>elf.GetPi</function-class>
        <function-signature>
          double getValue(java.lang.Double)
        </function-signature>
    </function>
</taglib>


uri 는 태그 라이브러리에 등록하는 부분
name 은 JSP 에서 사용할 메서드 이름
function-class 는 실제 사용 클래스
function-signature 는 사용할 메서드 형태 (인자값 사용가능) 

3. JSP 에 taglib 지시자를 코딩한다
4. EL 에서 함수를 호출한다

elfTest.jsp


<
%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="elf" uri="elfunction"%>

<html>
    <body>
        <h1>PI + 6.55 = </h1>
        <h1>${elf:pi(6.55)}</h1>
    </body>
</html>

결과는

PI + 6.55 = 9.69

posted by 헤이장
2009. 7. 27. 20:31 Web/Jsp


더하기 +
빼기 -
곱하기 *
나누기 / div
나머지 % mod 

AND && and
OR || or
NOT ! not

등호 == eq
부등호 != ne
~보다 작다 < lt
~보다 크다 > gt
~보다 작거나 같다 <= le
~보다 크거나 같다 >= ge

 
예약어 

true -
false - 거짓
null -
instanceof
empty null 또는 비어있는지 체크하기 위한 연산자


posted by 헤이장
2009. 7. 27. 20:26 Web/Jsp

※ JSP 코드에서 자바소스를 사용할 수 없도록 하기

 DD 에서 설정 (web.xml)

<web-app>
 

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <scripting-invalid>true</scripting-invalid>
        </jsp-property-group>
    </jsp-config> 

</web-app>


EL 무시하게 하기

 DD 에서 설정 (web.xml)


<web-app>
 

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <el-ignored>true</el-ignored>
        </jsp-property-group>
    </jsp-config>

</web-app>


 JSP 페이지에서


<
%@page isELIgnored="true" %>


DD 에서 설정하면 모든 페이지에 적용이 되고
JSP 페이지에서의 선언이 DD 에서의 선언보다 우선시 된다

posted by 헤이장
2009. 7. 27. 13:39 Web/Jsp

로그인 시 아이디 저장하기 옵션 처럼
아이디를 저장해두고 싶은 경우
쿠키를 사용 하면 된다 

쿠키 저장하기 

Cookie cookie = new Cookie("id",id);
객체 생성

cookie.setMaxAge(-1);
브라우저가 종료될때까지 유지 

cookie.setMaxAge(24*60*60);
단위는 초
24시간동안 쿠키를 유지하게 한다
이렇게 하면 일주일 한달이라도 id 값을 쿠키로 가지고 있을 수 있다 

response.addCookie(cookie);
쿠키를 응답에 저장
 

쿠키에서 불러오기 

Cookie[] cookie = req.getCookies();
int cLen = cookie.length;
for (int i = 0; i < cLen; i++) {
    if (cookie[i].getName().equals("id")) {
        System.out.println("세션에 저장된 id 값은? " + cookie[i].getValue());
    }
}

posted by 헤이장
2009. 7. 27. 13:36 Web/Jsp

< HttpSession 메서드 >

getCreationTime() - 세션 생성 시간
getLastAccessedTime() - 마지막 요청 시간
setMaxInactiveInterval() - 최대허용시간 설정 (초)
getMaxInactiveInterval() - 최대허용시간
invalidate() - 세션 제거

< 타임아웃 설정하기 > - 일정 시간 동안 요청이 없으면 세션을 제거한다 

1. DD에서 전체 세션 타임아웃 설정
      web.xml

<web-app ... >
    <servlet>

         ...
    </servlet>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
</web-app>

※ 단위는

  

2. 특정 세션만 타임아웃 설정

session.setMaxInactiveInterval(1800);
session.setMaxInactiveInterval(30*60);

※ 단위는

posted by 헤이장