Jsp - EL 함수 정의 하여 사용

Posted 05 3, 2009 14:10, Filed under: Language/ㅡ Jsp

### 로직 구현 클래스 파일
package kr.co.sunshiny.tld;

public class DiceRoller {
        public static int rollDice(){
                return (int)((Math.random() * 10) + 1);
        }
}


### tld 정의 파일
위치 : tld파일 위치는 WEB-INF/ 하위에 존재 하도록설정 
예)WebContent/WEB-INF/conf/tld/
# 애플리케이션이 배포될때, 컨테이너는 WEB-INF와 그 하위 디렉토리를 뒤져서 tld 파일을 모두 찾음.
# (JAR 파일일 경우 WEB-INF/lib). 파일을 찾으면 "이 이름을 가진 URI를 가진 TLD의 실제 파일은 어느 위치에 있다"와 같이 맵정보를 만듬.

<?xml version="1.0" encoding="ISO-8859-1" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="htttp://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
        <tlib-version>1.2</tlib-version>
        <uri>DiceFunctions</uri>
        <function>
                <name>rollIt</name>
                <function-class>kr.co.sunshiny.tld.DiceRoller</function-class>
                <function-signature>
                        int rollDice()
                </function-signature>
        </function>
</taglib>


### jsp 에서 사용
  <%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
   
<%@ taglib prefix="mine" uri="DiceFunctions" %>  
   
<!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>
       
rollIt() : ${mine:rollIt()}<br/>       
       
</body>
</html>
05 3, 2009 14:10 05 3, 2009 14:10

Trackback URL : http://develop.sunshiny.co.kr/trackback/208

Leave a comment

Jsp - HttpServlet 기본적인 요청 방법

Posted 05 3, 2009 12:27, Filed under: Language/ㅡ Jsp

### web.xml

<?
xml version="1.0" encoding="ISO-8859-1"?>

<web-app 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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

  <display-name>Webdav Content Management</display-name>
  <description>
     Webdav Content Management
  </description>

   <servlet>
    <servlet-name>simple</servlet-name>
    <servlet-class>jsp.controller.SimpleController</servlet-class>
  </servlet>

  <servlet>
    <servlet-name>actionServlet</servlet-name>
    <servlet-class>jsp.controller.ActionServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>actionServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file/>
  </welcome-file-list> 

</web-app>


### Controller
package jsp.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;

public class SimpleController extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
                // 모든 요청과 응답을 processRequest 메소드로 받음
                this.processRequest(request, response);
        }
        public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
                this.processRequest(request, response);
        }
        // 사용자 정의 요청을 처리 하는 내부 메소드
        private void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
                System.out.println("요청 들어옴");
                //1. 요청분석
                String type = request.getParameter("type");
                /**
                 *  ?type=date
                 *  ?type=greeting
                 *  3. 
                 */
                //2. 요청에 맞는일 수행

                Object resultObject = null;
                if(type == null){
                        resultObject ="type == null ";
                        //  equals 에서 type의 값이 null 이면 자동으로 에러
                }else if(type.equals("greeting")){
                        resultObject = "안녕하세요 ~!";
                }else if(type.equals("date")){
                        resultObject = new java.util.Date();
                }
                //3. 결과를 request에 객체 setAttribute 한다.
                request.setAttribute("result", resultObject);
                //            4. view(JSP) 선택후에 view 로 forwording......
                RequestDispatcher dispatcher = request.getRequestDispatcher("/simpleView.jsp");
                dispatcher.forward(request, response);
        }      
}



### jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
        Object result = request.getAttribute("result");
%>
<h1> SimpleController로 부터 받은 데이타 </h1>
<hr>
<!-- toString 이 자동으로 호출됩 -->
<%=result %>
</body>
</html>
05 3, 2009 12:27 05 3, 2009 12:27

Trackback URL : http://develop.sunshiny.co.kr/trackback/207

Leave a comment


Recent Posts

  1. Linux - Telnet 서비스 비활성및 실행
  2. NT - 서버 원격데스크탑 연결
  3. NT - http와 https간에 세션 공유가...
  4. Unix - 대량 파일 이동, 삭제시 Argu...
  5. Oracle - SYS_CONTEXT 함수를 이용하...

Recent Comments

  1. 네. 고맙습니다^^ 행복한 한해 보... sunshiny 01 16,
  2. sunshiny님. 안녕하세요... 올려 주... yihans 01 16,
  3. 답글 주셔서 고맙습니다^^ 소스 복... sunshiny 01 11,
  4. 관리자만 볼 수 있는 댓글입니다. 비밀방문자 01 11,
  5. 넵 답변감사합니다^^ 좋은 하루 되... 노로링

Recent Trackbacks

  1. 윈도우 cmd 명령어 팁 월풍도원(月風道院) - Delight on th... %M
  2. 파일 압축 Like RadioHead %M
  3. Mysql - mysql 설치후 Character set... 멀고 가까움이 다르기 때문 %M

Calendar

«   02 2012   »
      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      

Bookmarks

  1. 위키피디아
  2. MysqlKorea
  3. Oracle All Documentation
  4. 엑셈
  5. 오라클 클럽
  6. 네이버개발자센터
  7. API - Java
  8. API - Spring
  9. Java Community
  10. Reference - Spring
  11. 스프링사용자
  12. 자바지기
  13. Ready System
  14. Solaris Freeware
  15. Linux-Site
  16. RedHat Korea
  17. 윈디하나의 솔라나라

Site Stats

TOTAL 217714 HIT
TODAY 16 HIT
YESTERDAY 115 HIT