cf.

JSP 2.0

JSP¤Î¹½Â¤

¥Æ¥ó¥×¥ì¡¼¥È¥Æ¥­¥¹¥È

  1. HTML / XML
  2. ¥³¥á¥ó¥È¤Î°ã¤¤¤ËÃí°Õ
    <!-- XML¤Î¥³¥á¥ó¥È -->
    <%-- JSP¤Î¥³¥á¥ó¥È -->
    <%// JSP¤Î¥³¥á¥ó¥È(°ú¤Ã¤«¤±ÌäÂê) %>

¥Ç¥£¥ì¥¯¥Æ¥£¥Ö

page ¥Ç¥£¥ì¥¯¥Æ¥£¥Ö

  1. ½ñ¼°
    1. ¥¹¥Ú¡¼¥¹¶èÀÚ¤ê¤ÇÊ£¿ô¤Î°À­¤òµ­½Ò¤·¤Æ¤â¤è¤¤¤·
       <%@ page buffer="128kb" autoFlash="false" %>
      
    2. Ê̤Îpage¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤Ë¤·¤Æ¤â¤è¤¤
       <%@ page buffer="128kb" %>
       <%@ page autoFlash="false" %>
      
  2. 13¼ïÎà
    1. JSP¥·¥ó¥¿¥Ã¥¯¥¹(ÀßÄêÃͤϥǥե©¥ë¥ÈÃÍ)
       <%@ page language="java" %>
       <%--
       <%@ page extends="" %>
       --%>
       <%@ page import="java.lang.*,javax.servlet.*,javax.servlet.http.*,javax.servlet.jsp.*" %>
       <%@ page session="true" %>
       <%@ page buffer="8kb" %>
       <%@ page autoFlash="true" %>
       <%@ page isThreadSafe="true" %>
       <%--
       <%@ page info="" %>
       --%>
       <%@ page isErrorPage="false" %>
       <%--
       <%@ page errorPage="" %>
       --%>
       <%@ page contentType="text/html;charset=ISO-8859-1" %>
       <%--
       <%@ page pageEncoding="contentType¤Îcharset" %>
       --%>
       <%@ page isELIgnored="false" %>
      
    2. XML¥·¥ó¥¿¥Ã¥¯¥¹
       <jsp:directive.page language="java" />
       <!--
       <jsp:directive.page extends="" />
       -->
       <jsp:directive.page import="java.lang.*,javax.servlet.*,javax.servlet.http.*,javax.servlet.jsp.*" />
       <jsp:directive.page session="true" />
       <jsp:directive.page buffer="8kb" />
       <jsp:directive.page autoFlash="true" />
       <jsp:directive.page isThreadSafe="true" />
       <!--
       <jsp:directive.page info="" />
       -->
       <jsp:directive.page isErrorPage="false" />
       <!--
       <jsp:directive.page errorPage="" />
       -->
       <jsp:directive.page contentType="text/html;charset=ISO-8859-1" />
       <!--
       <jsp:directive.page pageEncoding="contentType¤Îcharset" />
       -->
       <jsp:directive.page isELIgnored="false" />
      
  3. °À­¤Î³µÎ¬
    °À­³µÎ¬
    languageJSP2.0¤Ç¤Ï"java"¤Î¤ß
    extends¤³¤ÎJSP¤«¤éServlet¤ò¥×¥ê¥³¥ó¥Ñ¥¤¥ë¤¹¤ëºÝ¤Ë·Ñ¾µ¤¹¤ë¥¯¥é¥¹
    import¤³¤ÎJSP¤Ç»È¤¦¥¯¥é¥¹¡£¥Ç¥Õ¥©¥ë¥È¤Çimport¤µ¤ì¤Æ¤¤¤ë°Ê³°¤Î¥¯¥é¥¹¤ò»È¤¦¤È¤­¤Ë¤Ï ­¡<%@ page import="¡Á"%> ¤Ë¥«¥ó¥Þ¶èÀÚ¤ê¤Çµ­½Ò¤¹¤ë¤«¡¢­¢<%@ page import="¡Á"%> ¤òÊ£¿ôµ­½Ò¤¹¤ë
    session°ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È session ¤ò»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
    buffer,autoFlashHTML¤ò½ÐÎϤ¹¤ëºÝ¤Î¥Ð¥Ã¥Õ¥¡¥µ¥¤¥º¡£autoFlash="false"¤Ë¤¹¤ë¤È¡¢¥Ð¥Ã¥Õ¥¡¤«¤é¤¢¤Õ¤ì¤¿¤È¤­ ServletException? ¤òµ¯¤³¤¹
    isThreadSafe?true¸ÇÄê¿ä¾©¡£¤³¤ÎJSP¤Ï¥¹¥ì¥Ã¥É¥»¡¼¥Õ¤Ëºî¤é¤ì¤Æ¤¤¤ë¤«¡©
    info"Copyright (C) 1995-2006 KAGYUU CORPORATION, All Rights Reserved." ¤Ê¤É
    isErrorPage?°ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È exception ¤ò»È¤¨¤ë¤è¤¦¤Ë¤¹¤ë
    errorPage¤³¤ÎJSP¤ÇÎ㳰ȯÀ¸»þ¤ËÁ«°Ü¤¹¤ëJSP¡£Á«°ÜÀè¤ÎJSP¤Ç¤Ï°ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È exception ¤ÇȯÀ¸¤·¤¿Îã³°¤ò»²¾È²Äǽ
    contentType"text/html;charset=Windows31-J"¤Ê¤É
    pageEncoding"Windows31-J"¤Ê¤É
    isELIgnoredEL¼°¤ò̵»ë¤¹¤ë¤«¡©

include ¥Ç¥£¥ì¥¯¥Æ¥£¥Ö

  1. JSP¤«¤éServlet¤Ø¤Î¥×¥ê¥³¥ó¥Ñ¥¤¥ë»þ¤ËÀÅŪ¤Ë¼è¤ê¹þ¤Þ¤ì¤ë»ñ»º
    (¤Ä¤Þ¤ê¤Ï¡¢Servlet¤ÎJava¥³¡¼¥É¤Ë¼è¤ê¹þ¤Þ¤ì¤ë)
  2. ɸ½à¥¢¥¯¥·¥ç¥ó <jsp:include> ¤È¤Î°ã¤¤¤ËÃí°Õ
  3. JSP¥·¥ó¥¿¥Ã¥¯¥¹
    <%@ include file="¥Ñ¥¹" %>
  4. XML¥·¥ó¥¿¥Ã¥¯¥¹
    <jsp.directive.include file="¥Ñ¥¹" />

taglib ¥Ç¥£¥ì¥¯¥Æ¥£¥Ö

  1. tagÄêµÁ
  2. JSP¥·¥ó¥¿¥Ã¥¯¥¹
    1. ¥¿¥°¥Ï¥ó¥É¥é
      <%@ taglib uri="TLD¥Õ¥¡¥¤¥ë¤ÎURI" prefix="JSPÆâ¤Ç»È¤ï¤ì¤ë¥¿¥°Ì¾" %>
      URI»ØÄêË¡Îã
      JSP¤«¤é¤ÎÁêÂХѥ¹snail.tld
      ContextRoot?¤«¤é¤ÎÁêÂХѥ¹/WEB-INF/snail.tld
      web.xml¤Ç»ØÄꤷ¤¿ÏÀÍýURLhttp://hondou.homedns.org/tags/snail.tld
      /WEB-INF/lib ¤ËÇÛÃÖ¤µ¤ì¤¿ Jar¥Õ¥¡¥¤¥ëÆâ¤Î /META-INF °Ê²¼¤Ë¤¢¤ë tld¥Õ¥¡¥¤¥ë ¤Ç»ØÄꤷ¤¿ÏÀÍýURLhttp://hondou.homedns.org/tags/snail.tld
    2. ¥¿¥°¥Õ¥¡¥¤¥ë
      <%@ taglib tagdir="/WEB-INF/tags" prefix="JSPÆâ¤Ç»È¤ï¤ì¤ë¥¿¥°Ì¾" %>
  3. XML¥·¥ó¥¿¥Ã¥¯¥¹
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
              xmlns:${JSPÆâ¤Ç»È¤ï¤ì¤ë¥¿¥°Ì¾}="${URI}"
              version="2.0>
    </jsp:root>

¥¹¥¯¥ê¥×¥Æ¥£¥ó¥°

¥¹¥¯¥ê¥×¥È¥ì¥Ã¥È

  1. JSP¥·¥ó¥¿¥Ã¥¯¥¹
    <% Java¥³¡¼¥É %>
  2. XML¥·¥ó¥¿¥Ã¥¯¥¹
    <jsp:scriptlet>Java¥³¡¼¥É</jsp:scriptlet>

Àë¸À

  1. JSP¤«¤é¥×¥ê¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿Servlet¤Î¥Õ¥£¡¼¥ë¥ÉÊÑ¿ô¡¢¥á¥½¥Ã¥ÉÀë¸À¡£
  2. JSP¥·¥ó¥¿¥Ã¥¯¥¹
    <%! int count; %>
    <%! int sum(int a,int b){
          return a+b;
        }
    %>
  3. XML¥·¥ó¥¿¥Ã¥¯¥¹
    <jsp:declarations> ¥Õ¥©¡¼¥ë¥ÉÊÑ¿ôÀë¸À¡¦¥á¥½¥Ã¥ÉÀë¸À </jsp:declarations>

JSP¼°

  1. ¼°¤ÎËöÈø¤Ë ; ¤¬ÉÕ¤«¤Ê¤¤¤³¤È¤ËÃí°Õ
  2. JSP¥·¥ó¥¿¥Ã¥¯¥¹
    <%= count %>
  3. XML¥·¥ó¥¿¥Ã¥¯¥¹
    <jsp:expression> count </jsp:expression>

EL¼°

  1. µ­½ÒÊýË¡
    ${¼°}
  2. EL¼°¤ò»È¤¨¤ë¤È¤³¤í¤È»È¤¨¤Ê¤¤¤È¤³¤í
    ¾ì½êÎã
    EL¼°¤ò»È¤¨¤ë¤È¤³¤í
    ¥Æ¥ó¥×¥ì¡¼¥È¥Æ¥­¥¹¥È¡£<FONT COLOR="RED">ËÜÆü${count}¿ÍÌܤΤªµÒÍÍ</FONT>
    ¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤Î°À­ÃÍ<%@ page pageEncoding="${charset}" %>
    ¥¢¥¯¥·¥ç¥ó(¥¿¥°)¤Î°À­ÃÍ<snail:code value="${code}"/>
    EL¼°¤ò»È¤¨¤Ê¤¤¤È¤³¤í
    ¥¹¥¯¥ê¥×¥È¥ì¥Ã¥È <% if(a=${count}){
    Àë¸À <%! int flag = ${count>10}; %>
    JSP¼° <%= ${count} %>
  3. °ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È
    elObject.png
    • ¤³¤ÎJSP¤Î¥½¡¼¥¹¤Ï¡¢ElObjectExam.jsp
    • ¤³¤Î¤Û¤«¤Ë pageContext ¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ë¡£¤³¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ÎÇÛ²¼¤Ë¡¢JSP¤Î°ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ë¡¦¡¦¡¦¤Ï¤º¤À¤¬¡¢Tomcat5.5.17¤Ç¤Ï¾å¼ê¤¯Æ°¤«¤Ê¤«¤Ã¤¿¡£°ì±þ¥Æ¥¹¥È¤Ë½Ð¤ë¤Î¤Ç¤Þ¤È¤á¤Æ¤ª¤¯¤È
      1. ${pageContext.page.???}
      2. ${pageContext.request.???}
      3. ${pageContext.session.???}
      4. ${pageContext.application.???}
      5. ${pageContext.response.???}
      6. ${pageContext.exception.???}
      7. ${pageContext.out.???}
      8. ${pageContext.config.???}
  4. ±é»»»Ò
    elOperator.png
  5. ͽÌó¸ì(ÊÑ¿ô̾¤È¤·¤Æ»È¤¨¤Ê¤¤Êª) 16¸Ä
     1.div    2.mod 
     3.eq     4.ne    5.lt 6.gt 7.le 8.ge
     9.and   10.or   11.not 
    12.true 13.false
    14.null 15.emoty 16.instanceof
  6. ¥Õ¥¡¥ó¥¯¥·¥ç¥ó
    1. EL¼°¤«¤éJava¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤ò»È¤¦¤³¤È¤¬½ÐÍè¤ë
      package com.snail.sjcwc;
      
      public final class ELFunctionExam {
        public static int sum(final int a,final int b){
          return a+b;
        }
        public static java.lang.String cat(final java.lang.String a,final java.lang.String b) {
          return a + b;
        }
      }
      
      • public static ¤ÇÄêµÁ¤¹¤ë
      • package ɬ¿Ü¡£¥Ç¥Õ¥©¥ë¥È¥Ñ¥Ã¥±¡¼¥¸¤Ï¥À¥á
    2. tld¥Õ¥¡¥¤¥ë¤ËÄêµÁ (Java SJC-WC tld#function)
      <?xml version="1.0" encoding="UTF-8"?>
      <taglib 
        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"
        version="2.0">
        <tlib-version>2.0</tlib-version>
        <short-name>FunctionExample</short-name>
        <function>
          <name>sum</name>
          <function-class>com.snail.sjcwc.ELFunctionExam</function-class>
          <function-signature>
            int sum(int,int)
          </function-signature>
        </function>
        <function>
          <name>cat</name>
          <function-class>com.snail.sjcwc.ELFunctionExam</function-class>
          <function-signature>
            java.lang.String cat(java.lang.String,java.lang.String)
          </function-signature>
        </function>
      </taglib>
      
      • <function-singature> ¤Ç¤Ï¡¢ÊÖÃÍ¡¦°ú¿ô¤Ï´°Á´½¤¾þ̾¤Çµ­½Ò¤¹¤ë
    3. JSP¤Ç¤Ï¡¢tld¤ÇÄêµÁ¤·¤¿Ì¾Á°¤Ç»È¤¦
      <%@ page contentType="text/html;charset=Windows-31J" %>
      <%@ taglib uri="/WEB-INF/func.tld" prefix="myFunc" %>
      
      <head>
      <title>EL Function Example</title>
      </head>
      
      <body>
      
      <table border="1">
      <tr><td>SUM</td><td>${myFunc:sum(1,2)}</td></tr>
      <tr><td>CAT</td><td>${myFunc:cat("¤Í¤³","¤Í¤³¤í¤ó¤À")}</td></tr>
      </table>
      
      </body>
      
      </head>
      
    4. ¼Â¹Ô·ë²Ì
      elFunc.png

¥¢¥¯¥·¥ç¥ó

tagDiagram.png

¥¯¥é¥·¥Ã¥¯¥¿¥°¥Ï¥ó¥É¥é

  1. ²òÀÏÂоݤÎJSP
    ­¡¥¿¥°É¾²ÁÁ°¤ÎJSP
    
    <my:exTag attr="3">    <%-- ³«»Ï¥¿¥°¤ò­¢¡¢Â°À­¤ò­£¤È¸Æ¤Ö¤³¤È¤Ë¤¹¤ë --%>
    
     ­¤BODY
    
    </my:exTag>            <%-- ½ªÎ»¥¿¥°¤ò­¥¤È¤¹¤ë --%>
    
    ­¦»Ä¤ê¤ÎJSP
  2. ¥¿¥°¤Ë¤è¤ëJSP½èÍý¥Õ¥í¡¼
    tagFlowChart.png
  3. ¤Þ¤º¤Ï°À­¤òÆɤ߼è¤ë¤À¤±¤Î¥¿¥°¥Ï¥ó¥É¥é
    tagAttr.png
    1. JSP(TagAttribute)
    2. ¥¿¥°¥Ï¥ó¥É¥é(TagAttribute)
    3. TLD(tag.tld)
  4. ¥¹¥¯¥ê¥×¥Æ¥£¥ó¥°ÊÑ¿ô¤È EVAL_BODY_AGAIN »È¤¦¥¿¥°¥Ï¥ó¥É¥é
    tagScripting.png
    1. JSP(TagIteration)
    2. ¥¿¥°¥Ï¥ó¥É¥é(TagIteration)
    3. TLD(tag.tld)
  5. ¥¿¥°¥Ü¥Ç¥£¤ÎÆɤ߼è¤ê
    tagBody.png
    • java.servlet.jsp.tagext.BodyContent? extends JSPWriter
      ¥á¥½¥Ã¥Éµ¡Ç½
      voidcleanBody()Body¤ò¥¯¥ê¥¢
      JSPWritergetEnclosingWriter?()JSPWriter¤ò¼èÆÀ
      ReadergetReader()Body¤ÎÆâÍƤò½ÐÎϤ¹¤ëReader¤ò¼èÆÀ
      StringgetString()Body¤ÎÆâÍƤòString¤È¤·¤Æ¼èÆÀ
      voidwriteOut(Write out)out¤Ë¡¢Body¤ÎÆâÍƤò½ÐÎÏ
    • doAfterBody?() ¤Ç¡¢pageContext.getOut():JSPWriter ¤Ë½ñ¤­¹þ¤ó¤ÀÆâÍƤϡ¢HTML¤Ç¤Ï¤Ê¤¯ bodyContent ¤Ë³ÊǼ¤µ¤ì¤ë¤è¤¦¤À
      • [[The tag body is " ¤¢¤¤¤¦¤¨¤ª ".]] ¤ÎÉôʬ
    • doEndTag?() ¤Ç¡¢pageContext.getOut():JSPWriter ¤Ë½ñ¤­¹þ¤ó¤ÀÆâÍƤϡ¢HTML¤Ë½ÐÎϤµ¤ì¤ë
      • ¥¿¥°¥Ü¥Ç¥£¤Ï¡Ö ¤¢¤¤¤¦¤¨¤ª [[The tag body is " ¤¢¤¤¤¦¤¨¤ª ".]]¡×¤Ç¤·¤¿ ¤ÎÉôʬ
    1. JSP(TagBody)
    2. ¥¿¥°¥Ï¥ó¥É¥é(TagBody)
    3. TLD(tag.tld)
  6. JSP¥Õ¥é¥°¥á¥ó¥È
    tagFragment.png
    • JSP¾å¤ÇÆüì¤Êµ­½ÒÊýË¡¤ò¤¹¤ë¥¿¥°
      <myTag:fragmentExam>
       <jsp:attribute name="attr">
         °À­ÃͤǤ¹
       </jsp:attribute>
       <jsp:body>
         ¥¿¥°BODY (&lt;jsp:body&gt;¥¿¥°¤ò»È¤¦!!)
       </jsp:body>
      </myTag:fragmentExam>
      • <jsp:attribute name="****"> ¤Ë¥¿¥°Â°À­¤òµ­½Ò¤¹¤ë
      • <jsp:body> ¤Ë¥¿¥°BODY¤òµ­½Ò¤¹¤ë (°ú¤Ã¤«¤±ÌäÂê¤ËÃí°Õ)
    1. JSP(JSPFragment#jsp)
    2. ¥¿¥°¥Ï¥ó¥É¥é(JSPFragment#java)
      public class FragmentExam extends BodyTagSupport {
      
         private JspFragment attr = null;
      
         public void setAttr(JspFragment param) { attr = param; }
         public JspFragment getAttr() { return attr; }
      
         public int doStartTag() throws JspException {
             // JspFragment#invoke(Write out)¤Ç¡¢HTML¤ËJSP¥Õ¥é¥°¥á¥ó¥È
             // ¤ò½ÐÎÏ¡£²¿²ó¤Ç¤â¸Æ¤Ó½Ð¤»¤ë
             getAttr().invoke(getAttr().getJspContext().getOut());
                 
             // null ¤ò»ØÄꤷ¤Æ¤â¾åµ­¤ÈƱ¤¸
             getAttr().invoke(null);
             return EVAL_BODY_BUFFERED;
         }
      ¡Ä
      • ¥¿¥°¥Ï¥ó¥É¥é¤Î¥Õ¥£¡¼¥ë¥É¤Ë JspFragment? ·¿¤ÎÊÑ¿ô¤òÍÑ°Õ¤¹¤ë(¤³¤³¤Ë¥¿¥°Â°À­¤¬³ÊǼ¤µ¤ì¤ë)
      • JspFragment? ¤ò HTML ¤Ë½ÐÎϤ¹¤ë¤È¤­¤Ë¤Ï invoke() ¥á¥½¥Ã¥É¤ò»È¤¦¡£
    3. TLD(tag.tld)
  7. ¿Æ¥¿¥°¤ÎÆɤ߼è¤ê
    tagParent.png
    • ¼¡¤ÎJSP¤ò²ò¼á
      <myTag:grandFather>
        <myTag:father>
          <myTag:child>
          </myTag:child>
        </myTag:father>
      </myTag:grandFather>
    • javax.servlet.jsp.tagext.TagSupport?
      ¥á¥½¥Ã¥Éµ¡Ç½
      TaggetParent()¿Æ¥¿¥°¤Î¥¿¥°¥Ï¥ó¥É¥é¤ò¼èÆÀ¤¹¤ë¡£Ìµ¤¤¾ì¹ç¤Ïnull
      TaggetAncestorWithClass?(Tag from, Class klass)³°Â¦¤Ë¤¢¤ë¤¹¤Ù¤Æ¤Î¥¿¥°¤ÎÃ椫¤é klass¥¿¥°¥Ï¥ó¥É¥é ¤ò¼èÆÀ¤¹¤ë¡£Ìµ¤¤¾ì¹ç¤Ïnull
    1. JSP(ParentTag)
    2. ¥¿¥°¥Ï¥ó¥É¥é(ParentTag)
    3. TLD(tag.tld)

¥·¥ó¥×¥ë¥¿¥°¥Ï¥ó¥É¥é

simpleTag.png

¥¿¥°¥Õ¥¡¥¤¥ë

  1. ¥¿¥°¤òJSP¤ÈƱ¤¸¹½Ê¸¤Î¥¿¥°¥Õ¥¡¥¤¥ë¤ÇÄêµÁ¤¹¤ë¤³¤È¤â½ÐÍè¤ë
  2. ÀßÃÖ¾ì½ê
    tagFile.png
    1. [Context Root]-[WEB-INF]-[tags] °Ê²¼(¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê¤â²Ä¤Ê¤³¤È¤ËÃí°Õ)
    2. [Context Root]-[lib] ¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë JAR¥Õ¥¡¥¤¥ë¤Î [META-INF]-[tags] °Ê²¼(¥µ¥Ö¥Ç¥£¥ì¥¯¥È¥ê¤â²Ä¤Ê¤³¤È¤ËÃí°Õ)
    3. ³ÈÄ¥»Ò¤Ï .tag ¤Þ¤¿¤Ï .tagx
  3. ¼ÂÁõÎã
    tagFileScreeshot.png
    • ¥¿¥°BODY¤ÎÆâÍƤˤĤ¤¤Æ¡¢¥¿¥°Â°À­from¤òto¤ËÁ´ÃÖ´¹¤¹¤ë¥¢¥¯¥·¥ç¥ó¤ò¥¿¥°¥Õ¥¡¥¤¥ë¤Ç¼ÂÁõ
    1. tfExam.jsp
      <%@ page contentType="text/html;charset=Windows-31J" %>
      <%@ taglib tagdir="/WEB-INF/tags" prefix="myTF" %>
      
      <html>
      <head>
      <title>Tag File Example</title>
      </head>
      
      <body>
      
      BEFORE TAG
      
      <hr/>
      
      <myTF:tfExam from="¥É¥Ê" to="DONA">
      ¤¢¤ëÀ²¤ì¤¿¡¡Ã뤵¤¬¤ê<br/>
      »Ô¾ì¤Ø¡¡¤Ä¤Å¤¯Æ»<br/>
      ²ÙÇϼ֤¬¡¡¥´¥È¥´¥È<br/>
      »Òµí¤ò¡¡¾è¤»¤Æ¤æ¤¯<br/>
      ²¿¤âÃΤé¤Ê¤¤¡¡»Òµí¤µ¤¨<br/>
      Çä¤é¤ì¤Æ¤æ¤¯¤Î¤¬<br/>
      ¤ï¤«¤ë¤Î¤À¤í¤¦¤«<br/>
      ¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê<br/>
      Èᤷ¤ß¤ò¤¿¤¿¤¨<br/>
      ¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê<br/>
      ¤Ï¤«¤Ê¤¤Ì¿<br/>
      </myTF:tfExam>
      
      <hr/>
      
      AFTER TAG
      
      </body>
      
      </html>
      
      • JSP¤ÎÊý¤ÏÄ̾ï¤ÈƱ¤¸
    2. tfExam.tag
      <%@ tag body-content="scriptless" %>
      <%@ attribute name="from" required="true" fragment="false"%>
      <%@ attribute name="to" required="true" fragment="false"%>
      
      <jsp:doBody var="bodyString" scope="request"/>
      
      <%= ((String)request.getAttribute("bodyString")).replaceAll(from,to) %>
      
      • tag¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¡¢attribute¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤Ç¡¢tld¥Õ¥¡¥¤¥ë¤ËÄêµÁ¤·¤¿ÆâÍƤòÄêµÁ
      • ¥¿¥°BODY¤Ï¡¢<jsp:dobody>¥¿¥°¤Ç¥¹¥³¡¼¥×¤Ë³ÊǼ¤¹¤ë
      • ¥¿¥°Â°À­¤Ï¡¢¤³¤Î¥¿¥°¥Õ¥¡¥¤¥ë¤«¤é¥×¥ê¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿Java¥¯¥é¥¹(¥¿¥°¥¯¥é¥¹¡Ë¤Î¥¤¥ó¥¹¥¿¥ó¥¹ÊÑ¿ô¤Ë³ÊǼ¤µ¤ì¤ë
  4. ¼ÂÁõÎã(JSP¥Õ¥é¥°¥á¥ó¥ÈÈÇ)
    1. tfExam2.jsp
      <%@ page contentType="text/html;charset=Windows-31J" %>
      <%@ taglib tagdir="/WEB-INF/tags" prefix="myTF" %>
      
      <html>
      <head>
      <title>Tag File Example</title>
      </head>
      
      <body>
      
      BEFORE TAG
      
      <hr/>
      
      <myTF:tfExam2>
        <jsp:attribute name="from">¥É¥Ê</jsp:attribute>
        <jsp:attribute name="to">DONA</jsp:attribute>
        <jsp:body>
      ¤¢¤ëÀ²¤ì¤¿¡¡Ã뤵¤¬¤ê<br/>
      »Ô¾ì¤Ø¡¡¤Ä¤Å¤¯Æ»<br/>
      ²ÙÇϼ֤¬¡¡¥´¥È¥´¥È<br/>
      »Òµí¤ò¡¡¾è¤»¤Æ¤æ¤¯<br/>
      ²¿¤âÃΤé¤Ê¤¤¡¡»Òµí¤µ¤¨<br/>
      Çä¤é¤ì¤Æ¤æ¤¯¤Î¤¬<br/>
      ¤ï¤«¤ë¤Î¤À¤í¤¦¤«<br/>
      ¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê<br/>
      Èᤷ¤ß¤ò¤¿¤¿¤¨<br/>
      ¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê¡¡¥É¥Ê<br/>
      ¤Ï¤«¤Ê¤¤Ì¿<br/>
        </jsp:body>
      </myTF:tfExam2>
      
      <hr/>
      
      AFTER TAG
      
      </body>
      
      </html>
      
      • JSP¤ÎÊý¤ÏÄ̾ï¤ÈƱ¤¸
    2. tfExam2.tag
      <%@ tag body-content="scriptless" %>
      <%@ attribute name="from" required="true" fragment="true" %>
      <%@ attribute name="to" required="true" fragment="true" %>
      
      <jsp:doBody var="bodyKey" scope="request"/>
      <jsp:invoke fragment="from" var="fromKey" scope="request"/>
      <jsp:invoke fragment="to" var="toKey" scope="request"/>
      
      <% 
        String bodyValue = (String)request.getAttribute("bodyKey");
        String fromValue = (String)request.getAttribute("fromKey");
        String toValue   = (String)request.getAttribute("toKey");
      %>
      <%= bodyValue.replaceAll(fromValue,toValue) %>
      
      • JSP¥Õ¥é¥°¥á¥ó¥È(¥¿¥°Â°À­)¤Ï¡¢<jsp:invoke>¥¿¥°¤Ç¥¹¥³¡¼¥×¤Ë³ÊǼ¤¹¤ë
  5. ¥¿¥°¥Õ¥¡¥¤¥ë¤Ç»È¤ï¤ì¤ë¥¢¥¯¥·¥ç¥ó¤ÎÀ°Íý
    1. <jsp:dobody>
      °À­ÀâÌÀÃÍ(¡û¥Ç¥Õ¥©¥ë¥ÈÃÍ)
      scope¥¿¥°BODY¤ÎÆâÍƤò¤É¤Î¥¹¥³¡¼¥×¤Ë³ÊǼ¤¹¤ë¤«?¡ûpage, request, session, application
      var¥¿¥°BODY¤ÎÆâÍƤòString·¿¤Ç³ÊǼ¤¹¤ë¾ì¹ç¤Î¥­¡¼ÃÍ
      varReader¥¿¥°BODY¤ÎÆâÍƤòReader·¿¤Ç³ÊǼ¤¹¤ë¾ì¹ç¤Î¥­¡¼ÃÍ
    2. <jsp:invoke>
      °À­ÀâÌÀÃÍ(¡û¥Ç¥Õ¥©¥ë¥ÈÃÍ)
      scope¥¿¥°Â°À­¤ÎÆâÍƤò¤É¤Î¥¹¥³¡¼¥×¤Ë³ÊǼ¤¹¤ë¤«?¡ûpage, request, session, application
      fragment¥¿¥°Â°À­Ì¾(JSP¥Õ¥é¥°¥á¥ó¥È̾)
      var¥¿¥°Â°À­¤ÎÆâÍƤòString·¿¤Ç³ÊǼ¤¹¤ë¾ì¹ç¤Î¥­¡¼ÃÍ
      varReader¥¿¥°Â°À­¤ÎÆâÍƤòReader·¿¤Ç³ÊǼ¤¹¤ë¾ì¹ç¤Î¥­¡¼ÃÍ
  6. ¥¿¥°¥Õ¥¡¥¤¥ë¤Ç»È¤ï¤ì¤ë¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤ÎÀ°Íý
    1. tag¥Ç¥£¥ì¥¯¥Æ¥£¥Ö
      JSP¥·¥ó¥¿¥Ã¥¯¥¹XML¥·¥ó¥¿¥Ã¥¯¥¹
      <%@ tag display-name="" %><jsp.directive.tag display-name="" >
      <%@ tag body-content="" %><jsp.directive.tag body-content="" >
      <%@ tag dynamic-attributes="true/false" %><jsp.directive.tag dynamic-attributes="" >
      <%@ tag small-icon="" %><jsp.directive.tag small-icon="" >
      <%@ tag large-icon="" %><jsp.directive.tag large-icon="" >
      <%@ tag description="" %><jsp.directive.tag description="" >
      <%@ tag example="" %><jsp.directive.tag example="" >
      <%@ tag language="java" %><jsp.directive.tag language="" >
      <%@ tag import="" %><jsp.directive.tag import="" >
      <%@ tag pageEncoding="" %><jsp.directive.tag pageEncoding="" >
      <%@ tag isELIgnored="true/false" %><jsp.directive.tag isELIgnored="" >
    2. attribute¥Ç¥£¥ì¥¯¥Æ¥£¥Ö
      JSP¥·¥ó¥¿¥Ã¥¯¥¹XML¥·¥ó¥¿¥Ã¥¯¥¹
      <%@ tag name="" %><jsp.directive.tag name="" >
      <%@ tag requreid="true/false" %><jsp.directive.tag requreid="" >
      <%@ tag fragment="true/false" %><jsp.directive.tag fragment="" >
      <%@ tag rtexprvalue="true/false" %><jsp.directive.tag rtexprvalue="" >
      <%@ tag type="java.lang.String" %><jsp.directive.tag type="" >
      <%@ tag description="" %><jsp.directive.tag description="" >
    3. variable¥Ç¥£¥ì¥¯¥Æ¥£¥Ö
      JSP¥·¥ó¥¿¥Ã¥¯¥¹XML¥·¥ó¥¿¥Ã¥¯¥¹
      <%@ tag name-given="" %><jsp.directive.tag ="" >
      <%@ tag name-from-attribute="" %><jsp.directive.tag ="" >
      <%@ tag alias="" %><jsp.directive.tag ="" >
      <%@ tag variable-class="" %><jsp.directive.tag ="" >
      <%@ tag declare="true/false" %><jsp.directive.tag ="" >
      <%@ tag scope="AT_BEGIN,AT_END,NESTED" %><jsp.directive.tag ="" >
      <%@ tag description="" %><jsp.directive.tag ="" >
  7. include¥Ç¥£¥ì¥¯¥Æ¥£¥Ö
  8. taglib¥Ç¥£¥ì¥¯¥Æ¥£¥Ö

JSP¤Î¼ÂÁõ

JSP¤Î¥é¥¤¥Õ¥µ¥¤¥¯¥ë

jspLifeCycle.png

JSP¤ÎÊÑ¿ô¥¹¥³¡¼¥×¤È°ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È

°ÅÌÛ¥ª¥Ö¥¸¥§¥¯¥È·¿¥¹¥³¡¼¥×
pageObjectpage¤³¤ÎJSP(¤«¤é¥×¥ê¥³¥ó¥Ñ¥¤¥ë¤µ¤ì¤¿¥µ¡¼¥Ö¥ì¥Ã¥È)¼«¿È
outJspWriter?pageJspContext?#getOut()
configServletConrig?pagePageContext?#getServletConfig?()
responseServletResponse?page_XXX#_jspService(req,res)
pageContextPageContext?pageJava SJC-WC#scope»²¾È
requestServletRequest?requestJava SJC-WC#scope»²¾È¡£_XXX#_jspService(req,res)
sessionHttpSession?sessionJava SJC-WC#scope»²¾È¡£page¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤Îsession°À­¤òtrue¤Ë¤¹¤ëɬÍפ¬¤¢¤ë(¥Ç¥Õ¥©¥ë¥È true)
applicationServletContext?applicationJava SJC-WC#scope»²¾È
exceptionThrowablepageJava SJC-WC#scope»²¾È¡£page¥Ç¥£¥ì¥¯¥Æ¥£¥Ö¤ÎisErrorPage°À­¤òtrue¤Ë¤¹¤ëɬÍפ¬¤¢¤ë(¥Ç¥Õ¥©¥ë¥È false)

JSP Config (web.xml)

ɸ½à¥¢¥¯¥·¥ç¥ó

Bean Áàºî

  1. <jsp:useBean>
    • ¥µ¡¼¥Ö¥ì¥Ã¥È¤ÎÆâÉôÊÑ¿ôid ¤Ë¡¢scope¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òÆɤ߽Ф¹
    • °À­
      ɬ¿Ü°À­ÀâÌÀ
      ¡ûid̾Á°
      ¢¤class´°Á´½¤¾þ¥¯¥é¥¹Ì¾
      ¢¤typeAbstract¥¯¥é¥¹Ì¾¡¢¥¤¥ó¥¿¥Õ¥§¡¼¥¹Ì¾
      ¢¤beanName¥ª¥Ö¥¸¥§¥¯¥È̾
      scopepage(¥Ç¥Õ¥©¥ë¥ÈÃÍ)¡¢request¡¢session¡¢application
    • °À­¤ÎÁȤ߹ç¤ï¤»
      °À­if scope.getAttribute("id")!=nullif scope.getAttribute("id")==null
      classclass id=scope.getAttribute("id")type id=new class()
      typetype id=scope.getAttribute("id")ERROR
      class+typetype id=scope.getAttribute("id")type id=new class()
      type+beanNametype id=scope.getAttribute("beanName")ERROR
  2. <jsp:setProperty>
    • name¥ª¥Ö¥¸¥§¥¯¥È¤Ë¡¢Ãͤò½ñ¤­¹þ¤à
    • °À­
      ɬ¿Ü°À­ÀâÌÀ
      ¡ûname̾Á° (+<jsp:useBean> ¤Î id)
      ¡ûpropertyÃͤò½ñ¤­¹þ¤à name Æâ¤Î¥Õ¥£¡¼¥ë¥É̾
      ¢¤value½ñ¤­¹þ¤àÃÍ(¨ÃÍ)
      ¢¤param½ñ¤­¹þ¤àÃÍ(HTTP REQUEST ¤Î¥Ñ¥é¥á¡¼¥¿Ì¾)
    • HTTP REQUEST ¤Î¼«Æ°Á´Å¾µ­
      <jsp:setProperty name="xxxBean" property="*"/>
       
      • ¤³¤ó¤Ê¤³¤È¤¬µ¯¤­¤ë
        for each paramName in HTTP-REQUEST
        {
          if( xxxBean ¤Ë¤Ï¡¢"paramName" ¤È¤¤¤¦¥Õ¥£¡¼¥ë¥É¤¬¤¢¤ë ){
            xxxBean.setParamName( HTTP-REQUEST.getParamName() );
          }
        }
  3. <jsp:getProperty>
    • name¥ª¥Ö¥¸¥§¥¯¥È¤«¤é¡¢ÃͤòÆɤ߹þ¤ß¡¢JSPWriter¤Ë½ÐÎϤ¹¤ë
    • °À­
      ɬ¿Ü°À­ÀâÌÀ
      ¡ûname̾Á° (+<jsp:useBean> ¤Î id)
      ¡ûpropertyÆɤ߹þ¤à name Æâ¤Î¥Õ¥£¡¼¥ë¥É¤Î̾Á°

Include / Forward

  1. <jsp: include>
    • JSP¼Â¹Ô»þ¤Ë¡¢Â¾¤ÎJSP¤ò¼è¤ê¹þ¤à
      <%@ include><jsp:include>
      ³µÍ×JSP¥×¥ê¥³¥ó¥Ñ¥¤¥ë»þ¤Ë¼è¤ê¹þ¤ß¼Â¹Ô»þ¤Ë¼è¤ê¹þ¤ß
      JSP¼è¤ê¹þ¤ß¡û¡û
      HTML¼è¤ê¹þ¤ß¡û¡û
      Servlet¼è¤ê¹þ¤ß¡ß¡û
      ¥Ñ¥é¥á¡¼¥¿°ú¤­ÅϤ·¡ß¡û
    • °À­
      ɬ¿Ü°À­ÀâÌÀ
      ¡ûpage¼è¤ê¹þ¤à»ñ»º¤ÎURL
      flushfalse(¥Ç¥Õ¥©¥ë¥È)/true
    • ¼ÂÁõÎã
      include.png
      • IncludeExam?.jsp
        <%@ page contentType="text/html;charset=Windows-31J" %>
        
        <html>
        
        <head>
        <title>JSP Include Example</title>
        </head>
        
        <body>
        
        ¢¦¿ÆJSP³«»Ï¢¦
        
        <hr/>
        
        <jsp:include page="/include.jsp" flush="true">
          <jsp:param name="name" value="Taro"/>
          <jsp:param name="tel" value="03-xxxx-xxxx"/>
          <jsp:param name="tel" value="090-yyyy-yyyy"/>
        </jsp:include>
        
        <hr/>
        
        ¢¤¿ÆJSP½ªÎ»¢¤
        
        </body>
        
        </html>
        
      • include.jsp
        <%@ page contentType="text/html;charset=Windows-31J" %>
        --¢¦»ÒJSP³«»Ï¢¦--
        <hr/>
        
        <table>
        <tr>
          <td>¡ð{param.name}</td>
          <td>=</td>
          <td>${param.name}</td>
        </tr>
        <tr>
          <td>¡ð{paramValues.tel[0]}</td>
          <td>=</td>
          <td>${paramValues.tel[0]}</td>
        </tr>
        <tr>
          <td>¡ð{paramValues.tel[1]}</td>
          <td>=</td>
          <td>${paramValues.tel[1]}</td>
        </tr>
        <tr>
          <td><%= request.getParameter("name") %></td>
          <td>=</td>
          <td><%= request.getParameter("name") %></td>
        </tr>
        <tr>
          <td><%= request.getParameterValues("tel")[0] %></td>
          <td>=</td>
          <td><%= request.getParameterValues("tel")[0] %></td>
        </tr>
        <tr>
          <td><%= request.getParameterValues("tel")[1] %></td>
          <td>=</td>
          <td><%= request.getParameterValues("tel")[1] %></td>
        </tr>
        
        </table>
        
        <hr/>
        --¢¤»ÒJSP½ªÎ»¢¤--
        
        <html> ¤ÏÉÔÍ×
  2. <jsp: fowrard>
    • JSP¼Â¹Ô»þ¤Ë¡¢Â¾¤ÎJSP¤Ëº¹¤·Âؤ¨¤ë
    • °À­
      ɬ¿Ü°À­ÀâÌÀ
      ¡ûpage¼è¤ê¹þ¤à»ñ»º¤ÎURL
      flushfalse(¥Ç¥Õ¥©¥ë¥È)/true
    • ¼ÂÁõÎã
      forward.png
      • ForwardExam?.jsp
        <%@ page contentType="text/html;charset=Windows-31J" %>
        
        <html>
        
        <head>
        <title>JSP Forward Example(Parent)</title>
        </head>
        
        <body>
        
        ¢¦¿ÆJSP³«»Ï¢¦
        
        <hr/>
        
        <jsp:forward page="/forward.jsp">
          <jsp:param name="name" value="Taro"/>
          <jsp:param name="tel" value="03-xxxx-xxxx"/>
          <jsp:param name="tel" value="090-yyyy-yyyy"/>
        </jsp:forward>
        
        <hr/>
        
        ¢¤¿ÆJSP½ªÎ»¢¤
        
        </body>
        
        </html>
        
      • forward.jsp
        <%@ page contentType="text/html;charset=Windows-31J" %>
        
        <html>
        
        <head>
        <title>JSP Forward Example(Child)</title>
        </head>
        
        <body>
        
        --¢¦»ÒJSP³«»Ï¢¦--
        <hr/>
        
        <table>
        <tr>
          <td>¡ð{param.name}</td>
          <td>=</td>
          <td>${param.name}</td>
        </tr>
        <tr>
          <td>¡ð{paramValues.tel[0]}</td>
          <td>=</td>
          <td>${paramValues.tel[0]}</td>
        </tr>
        <tr>
          <td>¡ð{paramValues.tel[1]}</td>
          <td>=</td>
          <td>${paramValues.tel[1]}</td>
        </tr>
        <tr>
          <td><%= request.getParameter("name") %></td>
          <td>=</td>
          <td><%= request.getParameter("name") %></td>
        </tr>
        <tr>
          <td><%= request.getParameterValues("tel")[0] %></td>
          <td>=</td>
          <td><%= request.getParameterValues("tel")[0] %></td>
        </tr>
        <tr>
          <td><%= request.getParameterValues("tel")[1] %></td>
          <td>=</td>
          <td><%= request.getParameterValues("tel")[1] %></td>
        </tr>
        
        </table>
        
        <hr/>
        --¢¤»ÒJSP½ªÎ»¢¤--
        
        </body>
        
        </html>
        
        <html> ¤¬É¬Í×

Applet

<jsp:plugin 
	type="bean|applet"  
	code="classFileName"  
	codebase="classFileDirectoryName"
	[ name="instanceName" ]
	[ archive="URIToArchive, ..." ] 
	[ align="bottom|top|middle|left|right" ]
	[ height="displayPixels" ]
	[ width="displayPixels" ]  
	[ hspace="leftRightPixels" ]
	[ vspace="topBottomPixels" ]
	[ jreversion="JREVersionNumber | 1.1" ]
	[ nspluginurl="URLToPlugin" ]
	[ iepluginurl="URLToPlugin" ] >

	[ <jsp:params>
		[ <jsp:param name="parameterName"  value="parameterValue" /> ]+
	</jsp:params> ]

	[ <jsp:fallback> text message for user </jsp:fallback> ]

</jsp:plugin>

tag¥Õ¥¡¥¤¥ë

  1. <jsp:invoke>
  2. <jsp:doBody>

XML¥·¥ó¥¿¥Ã¥¯¥¹

JSP SyntaxXML Syntax
<%-- ... --%><!-- ... -->
<%! ... %><jsp:declaration> ... </jsp:declaration>
<%@ include ... /><jsp:directive.include ... />
<%@ page ... /><jsp:dicectiove.page ... />
<%@ taglib uri="yyy" prefix="xxx" /><html xmlns:xxx="yyy"/> = <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:xxx="yyy" version="2.0>
<%= ... %><jsp:expression> ... </jsp:expression>
<% ... %><jsp:scriptlet> ... </jsp:scriptlet>
Template Data<jsp:text> ... </jsp:text>

XHTML

  1. JSP
    <?xml version="1.0" encoding="Windows-31J" ?>
    <jsp:root
      xmlns:jsp="http://java.sun.com/JSP/Page"
      version="2.0">
      
      <jsp:output
        omit-xml-declaration="false"
        doctype-root-element="html"
        doctype-public="-//W3C//DTD XHTML Basic 1.0//EN"
        doctype-system="http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd" />
        
      <jsp:element name="sector">
        <jsp:attribute name="name">accounting</jsp:attribute>
        <jsp:body>
          <jsp:element name="employee">
            <jsp:attribute name="name">Taro</jsp:attribute>
            <jsp:body>A-Class</jsp:body>
          </jsp:element>
          <jsp:element name="employee">
            <jsp:attribute name="name">Jiro</jsp:attribute>
            <jsp:body>B-Class</jsp:body>
          </jsp:element>
          <jsp:element name="employee">
            <jsp:attribute name="name">Sabro</jsp:attribute>
            <jsp:body>C-Class</jsp:body>
          </jsp:element>
        </jsp:body>
      </jsp:element>
    </jsp:root>
    
  2. ½ÐÎÏ
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
    <sector name="accounting">
      <employee name="Taro">A-Class</employee>
      <employee name="Jiro">B-Class</employee>
      <employee name="Sabro">C-Class</employee>
    </sector>
    
     
    <jsp:output omit-xml-declaration="xxx"><?xml version="1.0" encoding="UTF-8"?>¤Î½ÐÎÏ
    true or on (¥Ç¥Õ¥©¥ë¥ÈÃÍ)½ÐÎϤµ¤ì¤Ê¤¤
    false of off½ÐÎϤµ¤ì¤ë

JSTL

core

  1. taglibÀë¸À
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  2. set,out,remove
    JSTL.png
    • ¥½¡¼¥¹¥³¡¼¥É
    • ­¡set¥¿¥°¤Ï¥¹¥³¡¼¥×¤Ëʸ»úÎó¤ò³ÊǼ¤¹¤ë
      • ¥¹¥³¡¼¥×¤ËľÀܳÊǼ¤¹¤ë¤È¤­
        ɬ¿Ü°À­ÃÍ
        ¡ûvar¥»¥Ã¥È¤¹¤ëʸ»úÎó¤Î¥¹¥³¡¼¥×¤Ø¤Î³ÊǼ̾
        ¡ûvalue³ÊǼ¤¹¤ëʸ»úÎó
        scopepage(¥Ç¥Õ¥©¥ë¥È),request,session,application
      • ¥¹¥³¡¼¥×¤Ë³ÊǼ¤µ¤ì¤Æ¤¤¤ëMap/Bean¤Î°À­¤È¤·¤Æ³ÊǼ¤¹¤ë¤È¤­
        ɬ¿Ü°À­ÃÍ
        ¡ûtargetBean / Map ¤Î¥¹¥³¡¼¥×¤Ø¤Î³ÊǼ̾
        ¡ûproperty¥»¥Ã¥È¤¹¤ëʸ»úÎó¤Î Bean / Map Æâ¤Î°À­Ì¾
        ¡ûvalue³ÊǼ¤¹¤ëʸ»úÎó
        scopepage(¥Ç¥Õ¥©¥ë¥È),request,session,application
    • ­¤remove¥¿¥°¤Ï¥¹¥³¡¼¥×¤«¤é¥ª¥Ö¥¸¥§¥¯¥È¤òºï½ü¤¹¤ë
      ɬ¿Ü°À­ÃÍ
      ¡ûvarºï½ü¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¥¹¥³¡¼¥×¤Ø¤Î³ÊǼ̾
      scopepage(¥Ç¥Õ¥©¥ë¥È),request,session,application
  3. if,forEach
    JSTL2.png
    ¢¨[1,2,1,2,1,2]¤ÏLinkedList?
    • ¥½¡¼¥¹¥³¡¼¥É
    • c:forEach¤Îitem¤Ë»ØÄê¤Ç¤­¤ë¥ª¥Ö¥¸¥§¥¯¥È
      1. java.util.Collection (¥µ¥ó¥×¥ë­¡)
      2. java.util.Map
      3. java.util.Iterater
      4. java.util.Enumlation
      5. ÇÛÎó
      6. ¥«¥ó¥Þ¶èÀÚ¤ê¤Îʸ»úÎó
      7. java.servlet.jsp.jstl.sql.Result
    • c:if
      <c:if test="${item % 2 == 0}">
        <c:out value="${item} ¤Ï¡¢¶ö¿ô"/>
      </c:if>
    • test¤Îɾ²Á·ë²Ì¤ò³ÊǼ¤·¤¿¤¤¤È¤­¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë
      <c:if test="${item % 2 == 0}" var="isOdd" scope="request">
        <c:out value="${item} ¤Ï¡¢¶ö¿ô"/>
      </c:if>
      (scope="page(¥Ç¥Õ¥©¥ë¥ÈÃÍ) | request | session | application")
  4. forTokens,choose,when,otherwise
    JSTL3.png
    • ¥½¡¼¥¹¥³¡¼¥É
    • c:forToken ¤Ç¤Ï¡¢Ê¸»úÎó¤ò delims ¤Ç¶èÀÚ¤ë
    • c:choose
      <c:choose>
        <c:when test="<%= ((String)pageContext.getAttribute("item")).endsWith("»Ò") %>">
          female
        </c:when>
        <c:when test="<%= ((String)pageContext.getAttribute("item")).endsWith("Ϻ") %>">
          male
        </c:when>
        <c:otherwise>
          unknown
        </c:otherwise>
      </c:choose>
      
  5. url
    • JSP
      <c:url value="/index.jsp"/>
    • ½ÐÎÏ
      /SJCWC/index.jsp;jsessionid=1150DFC40563F6A89063760161236CC0
    • ÁêÂÐ¥¢¥É¥ì¥¹¢ªÀäÂÐ¥¢¥É¥ì¥¹
    • sessionid¤ÎÉÕ²Ã
  6. catch,import,redirect,param
    <c:catch var="exp">
      <c:import url="/include.jsp">
        <c:param name="name" value="Taro"/>
        <c:param name="tel" value="03-xxxx-xxxx"/>
        <c:param name="tel" value="090-yyyy-yyyy"/>
      </c:import>
    </c:catch>
    
    <c:if test="${not empty exp}">
      <c:redirect url="/error.jsp" context="exp">
        <c:param name="name" value="Taro"/>
      </c:redirect>
    </c:if>
    
    • c:catch ¥¨¥é¡¼¤Î¸¡½Ð
    • c:import
      • jsp:include¤ÈƱ¤¸
      • url°À­(jsp:include¤Ç¤Ïpage°À­) ¤Ï¡¢c:url ¤ÈƱÍͤËsessionid¤¬Éղ䵤ì¤ë
      • c:param ¤Ç¡¢¼è¤ê¹þ¤àJSP¤Ë¥Ñ¥é¥á¡¼¥¿¤òÅϤ¹¤³¤È¤¬¤Ç¤­¤ë
    • c:redirect
      • jsp:forward¤ÈƱ¤¸
      • url°À­(jsp:forward¤Ç¤Ïpage°À­) ¤Ï¡¢c:url ¤ÈƱÍͤËsessionid¤¬Éղ䵤ì¤ë
      • jsp:forward ¤È°ã¤¤¡¢¥³¥ó¥Æ¥Ê³°¤Î URL ¤ò»ØÄꤹ¤ë¤³¤È¤â½ÐÍè¤ë
      • context¤Ë¡¢exception ¤òÀßÄê¤Ç¤­¤ë
      • c:param ¤Ç¡¢Å¾Á÷ÀèJSP¤Ë¥Ñ¥é¥á¡¼¥¿¤òÅϤ¹¤³¤È¤¬¤Ç¤­¤ë

sql

  1. taglibÀë¸À
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
  2. data source ¤ÎÄêµÁ
    • JDBCÄêµÁ Java SJC-WC web.xml#resource-ref
    • sql¥¿¥°¤«¤é¤Î»²¾ÈÄêµÁ­¡ Java SJC-WC web.xml#context-param
      <context-param>
        <param-name>javax.servlet.jsp.jstl.sql.DataSource</param-name>
        <param-value>jdbc/TestDB</param-value>
      </context-param>
      
    • sql¥¿¥°¤«¤é¤Î»²¾ÈÄêµÁ­¢ JSPÆâ¤Ëµ­½Ò
      <sql:setDataSource dataSource="jdbc/TestDB">
      
      • var°À­¡¦scope°À­¤òÍøÍѤ¹¤ë¤È¡¢JSPÃæ¤ÇÊ£¿ô¤Î¥Ç¡¼¥¿¥½¡¼¥¹¤ò»È¤¦¤³¤È¤¬½ÐÍè¤ë
  3. select
    <sql:query var="queryResult"
      sql="SELECT * FROM ORDER_TABLE WHERE CUSTOMER_ID=? ORDER BY ORDER_DATE">
      <sql:param value="${id}"/>
    </sql:query>
    
    <c:forEach var="row" items="${queryResult.rows}>
      <c:out value="${row.order_date}/>
      <c:out value="${row.customer_id}/>
      <c:out value="${row.status}/>
      <br/>
    </c:forEach>
    
    • ¥Ú¡¼¥¸À©¸æ
       <sql:query var="queryResult" startRow="${start}" maxRows="50">
         ...
       </sql:query>
       <a href="<c:url url="/sql.jsp?start=${start-50}>Á°¤Î50·ï</a>
         
       <a href="<c:url url="/sql.jsp?start=${start+50}>¼¡¤Î50·ï</a>
      
    • ·ë²Ì¥»¥Ã¥È¤Ë´Þ¤Þ¤ì¤ë°À­
      °À­ÀâÌÀ
      queryResult.rows¸¡º÷¥»¥Ã¥È(SortedMap?·Á¼°)
      queryResult.rowsByIndex?¸¡º÷¥»¥Ã¥È(ÇÛÎó·Á¼°)
      queryResult.columnNamesÎó̾
      queryResult.rowCount·ë²Ì¥»¥Ã¥È¤Î¹Ô¿ô
      queryResult.limitedByMaxRows?¼¡¥Ú¡¼¥¸¤¬¤¢¤ë¤«¡©(¸¡º÷·ë²Ì¤Î¹Ô¿ô¤¬maxRow¤Ë㤷¤Æ¤¤¤ë¤«?)
  4. update / insert / delete
    <sql:transaction>
      <sql:update
        sql="UPDATE ORDER_TBLE SET STATUS=? WHERE ORDER_ID=?">
        <sql:param value="${stat}"/>
        <sql:param value="${id}"/>
      <sql:update>
      <sql:query
        sql="DELETE LOCK_TBLE WHERE LOCK_ID=?">
        <sql:param value="${lock}"/>
      <sql:update>
    </sql:transaction>
    

format

  1. taglibÀë¸À
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
  2. ¥Ç¥Õ¥©¥ë¥È¥í¥±¡¼¥ë¤ÎÀßÄê Java SJC-WC web.xml#context-param
    <context-param>
      <!-- ¥Ç¥Õ¥©¥ë¥È ¥í¥±¡¼¥ë -->
      <param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
      <param-value>ja</param-value>
      <!-- »ØÄꤵ¤ì¤¿¥í¥±¡¼¥ë¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Ê¤¤»þ¤Ë»È¤¦¥í¥±¡¼¥ë -->  
      <param-name>javax.servlet.jsp.jstl.fmt.fallBackLocale</param-name>
      <param-value>ja</param-value>
    </context-param>
    
  3. ¥í¥±¡¼¥ë¤ÎÀßÄê
    <fmt:setLocale value="jp"/>
    • HTTP HEADER ¤Î Accept-Language ¤ò¾å½ñ¤­
    • Ä̾ï¤Ï»È¤ï¤Ê¤¯¤Æ¤è¤¤
  4. HTTP REQUEST¤Î¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
    <fmt:requestEncoding value="UTF-8"/>
    • Ä̾ï¤Ï¥Õ¥£¥ë¥¿¤ò¤«¤Þ¤¹
    • J2EE¥³¥ó¥Æ¥Ê¤¬¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤·¤Æ¤«¤é¡¢JSP/Servlet ¤ËÀ©¸æ¤ò°Ü¤¹¼ÂÁõ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¾ì¹ç¤â¤¢¤ë(;·×¤Ê¤³¤È¤¹¤ë¤Ê!!)
  5. ¥á¥Ã¥»¡¼¥¸¥Õ¥¡¥¤¥ë¤ÎÍøÍÑ
    <fmt:setBundle basename="resources/application" var="msg" />
    <fmt:message key="err.msg1" bundle="${msg}/>
    
    • ¥í¥±¡¼¥ë¤Ë¤è¤ê½ÐÎÏ¥Õ¥¡¥¤¥ë¤ÎÆâÍƤ¬°ã¤¦
    • jp¤Î¾ì¹ç¡¢resources/application_jp.properties ¤Î¼¡¤Î¹Ô¤¬»È¤ï¤ì¤ë
      err.msg1=make: *** ¥¿¡¼¥²¥Ã¥È `gril-friend' ¤ò make ¤¹¤ë¥ë¡¼¥ë¤¬¤¢¤ê¤Þ¤»¤ó¡£Ãæ»ß¡£
    • en¤Î¾ì¹ç¡¢resources/application_en.properties ¤Î¼¡¤Î¹Ô¤¬»È¤ï¤ì¤ë
      err.msg1=make: *** No rule to make target `gril-friend'.  Stop.

xml

  1. taglibÀë¸À
    <%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
  2. x:transform
    • XSLT¤ÎŬÍÑ
  3. x:parse
    • DOM¤Ø¤Î³ÊǼ
  4. x:out
    • x:parse ¤Ç¼èÆÀ¤·¤¿ DOM ¥ª¥Ö¥¸¥§¥¯¥È¤«¤é¡¢XPath¤Ç»ØÄꤷ¤¿Í×ÁǤΤòÈ´¤­½Ð¤·¤Æ½ÐÎÏ

»²¹Íʸ¸¥

  1. JSR-000152 JavaTM JSP 2.0 »ÅÍͽñ, http://jcp.org/en/jsr/detail?id=152 (¤³¤Á¤é¤ò¼ç¤ËÊÙ¶¯)
  2. SUN¶µ²Ê½ñ Web¥³¥ó¥Ý¡¼¥Í¥ó¥È¥Ç¥Ù¥í¥Ã¥Ñ(SJC-WC 310-81),æƱɼÒ,ÊÆ»³³Ø,2006 (Êä­»ñÎÁ¡¢Îý½¬ÌäÂê)
    479811104X
  3. JSR-000052 JSP Standard Tag Library »ÅÍͽñ, http://jcp.org/en/jsr/detail?id=52
  4. 10Æü¤Ç¤ª¤Ü¤¨¤ëJakartaÆþÌ綵¼¼, æƱ˼Ò, »³Åľʹ², 2003
    4798104396
  5. JSTLÆþÌç: ¼°¸À¸ì, IBM Developer Works, Mark A. Kolb(IBM), 2003, http://www-06.ibm.com/jp/developerworks/java/030411/j_j-jstl0211.shtml
  6. JSTLÆþÌç: ³Ë¿´(core)¤Ë¿¨¤ì¤ë, Mark A. Kolb(IBM), 2003, http://www-06.ibm.com/jp/developerworks/java/030516/j_j-jstl0318.shtml
  7. JSTLÆþÌç: ¥×¥ì¥¼¥ó¥Æ¡¼¥·¥ç¥ó¤¬¤¹¤Ù¤Æ, IBM Developer Works, Mark A. Kolb(IBM), 2003, http://www-06.ibm.com/jp/developerworks/java/030620/j_j-jstl0415.shtml
  8. JSTLÆþÌç Âè4²ó:SQL¤ª¤è¤ÓXML¥³¥ó¥Æ¥ó¥Ä¤Ø¤Î¥¢¥¯¥»¥¹, IBM Developer Works, Mark A. Kolb(IBM), 2003, http://www-06.ibm.com/jp/developerworks/java/030718/j_j-jstl0520.shtml

Java


źÉÕ¥Õ¥¡¥¤¥ë: filetagFileScreeshot.png 2540·ï [¾ÜºÙ] filetagScripting.png 2574·ï [¾ÜºÙ] fileelObject.png 2521·ï [¾ÜºÙ] filetagFlowChart.png 2851·ï [¾ÜºÙ] fileelOperator.png 2420·ï [¾ÜºÙ] fileJSTL.png 2289·ï [¾ÜºÙ] fileforward.png 2094·ï [¾ÜºÙ] filetagDiagram.png 2432·ï [¾ÜºÙ] fileelFunc.png 2311·ï [¾ÜºÙ] filetagBody.png 2536·ï [¾ÜºÙ] filetagFragment.png 2583·ï [¾ÜºÙ] filetagAttr.png 2477·ï [¾ÜºÙ] fileinclude.png 2184·ï [¾ÜºÙ] filetagParent.png 2761·ï [¾ÜºÙ] fileJSTL3.png 2397·ï [¾ÜºÙ] fileJSTL2.png 2255·ï [¾ÜºÙ] filejspLifeCycle.png 2574·ï [¾ÜºÙ] filesimpleTag.png 2393·ï [¾ÜºÙ] filetagFile.png 2586·ï [¾ÜºÙ]

¥È¥Ã¥×   ÊÔ½¸ Åà·ë²ò½ü º¹Ê¬ ¥Ð¥Ã¥¯¥¢¥Ã¥× źÉÕ Ê£À½ ̾Á°Êѹ¹ ¥ê¥í¡¼¥É   ¿·µ¬ °ìÍ÷ ñ¸ì¸¡º÷ ºÇ½ª¹¹¿·   ¥Ø¥ë¥×   ºÇ½ª¹¹¿·¤ÎRSS   sitemap
Last-modified: 2007-01-21 (Æü) 18:33:56 (6526d)
Short-URL:
ISBN10
ISBN13
9784061426061