Chapter 3 : / Hello JSP Hello (?) Hello jsp List 31 <html> <body> <center> <h1>hello jsp</h1> </center> </body> </html> hellojsp jsp? html tag jsp jsp jsp 31 http://wwwjava2xmlcom
hello jsp List 32 <html> <body> <center> <h1><%= hello jsp %></h1> </center> </body> </html>, [ 3-1] Html Jsp expression Hello jsp List 33 <html> <body> <center> <h1><jsp:expression>hello jsp</jsp:expression></h1> </center> </body> </html> List 32List33 (?)? jsp xml xml : List33 Jspxml tag Tomcat321, Resin123, Hello jsp? http://wwwjava2xmlcom
List 34 package comboolpaejsp; public class HelloBean{ String hello = Hello jsp ; public String gethello(){ return hello; } public void sethello(string hello){ thishello = hello; } } List 35 <jsp:usebean id= hello class= comboolpaejsphellobean /> <jsp:setproperty name= hello property= hello /> <html> <body> <center> <h1><jsp:getproperty name= hello property= hello /></h1> </center> </body> </html> 34/35 class classpath jsp hello jsp? (?) List 36 package comboolpaejsp; import javaxservletjsp*; import javaxservletjsptagext*; import javaio*; import javaxservlet*; public class HelloTag extends TagSupport{ String value; public int dostarttag(){ try{ http://wwwjava2xmlcom
} } JspWriter out = pagecontextgetout(); outprint("hello jsp"); }catch(ioexception e){ Systemoutprintln(e); } return SKIP_BODY; List 36custom tag, jsp, class List 37 tld TLD(tag library descripter) List 37 <?xml version="10" encoding="iso-8859-1"?> <!DOCTYPE taglib PUBLIC "-//Sun MicroSystems, Inc //DTD JSP Tag Library 11//EN" "http://javasuncom/j2ee/dtds/web-jsptaglibrary_1_1dtd"> <taglib> <tlibversion>10</tlibversion> <jspversion>11</jspversion> <shortname>jspace</shortname> <urn/> <info> JavaServer Pages </info> <tag> <name>hello</name> <tagclass>comboolpaejsphellotag</tagclass> <info>simple example : Hello jsp</info> <bodycontent>empty</bodycontent> </tag> </taglib> List 38 jsp xml <tag> <name> hello Jsp tld (List 37 xml ) tld ( hello) class(list 36 ) comboolpaejsphellotag custom tag http://wwwjava2xmlcom
List 38 <%@ taglib uri="web-inf/classes/tld/hellotld" prefix="jspace" %> <html> <body> <center> <h1> <jspace:hello /> </h1> </center> </body> </html> jsp hello jsp Hello jsp Hello jsp Hello JSP jsp (?), JSP Jsp JSP 1 2 jsp80%, ( ) ( ),? http://wwwjava2xmlcom
(?) jsp JavaBeans, Custom Tag, Servlet jsp Servlet jsp, servlet jsp (Element Syntax) jsp ( ) Jsp jsp 1 Directives 2 Scripting Elements 3 Actions Directives Directives jsp <%@ directive {attr= value }* %> : EBNF EBNF {} 0 1, * http://wwwjava2xmlcom
page, include, taglib page Directive jsp, Jsp <%@ page attributelist %> attributelist ::= {language= scriptinglanguage } {extends = classname } {import = importlist } {session = true false } {buffer = none sizekb } {autoflush = true false } {istreadsafe = true false } {info = info_text } {errorpage = error_url } {iserrorpage = true false } {contenttype = contenttype information } ::= attributelist11 ( ) or (or ), <%@ page language= java extends= javaxservletjsphttpjsppage import= javautil* session= false buffer= 8kb autoflus= true istreadsafe= true info= This page is example page errorpage= /error/error01jsp iserrorpage= false contenttype= text/html;charset=euc-kr %> http://wwwjava2xmlcom
import import List <%@ page contenttype= text/plain %> <%@ page contenttype= text/html %> (Default) Default ( ) language java (?) (??? ) extends jsp super jsp jsp request jsp response jakarta-tomcat-321\work\ extends jsp javaxservletjsphttpjsppage (implements)? (?)jsp import jsp java package full name? Date javautil javasql URI? * jsp import java http://wwwjava2xmlcom
import import list (,) <%@ page import= javasql*, javautil*, comboolpaejsphelloclass %> import javalang*, javaxservlet*, javaxservletjsp*, javaxservlethttp* javalang String, import?, javaxservlet (?) jspweb jsp Cookie c = new Cookie( id, bluenote ); javaxservlethttp session jsp session true false true true session( javaxservlethttphttpsession ) false session session Session buffer jsp JspWriter(JavaxservletjspJspWriter) jsp JspWriter autoflush java (javaservlet ~ ~ ) kb, none 8kb ~ autoflush JspWriter Buffer http://wwwjava2xmlcom
true / false true false buffer (overflow) buffer= none autoflush= false Buffer isthreadsafe jsp SingleThreadModel true / false true true thread, false SingleThreadModel Thread false true true, false,, DB (syncronized) SingleThreadModel info ServletgetServletInfo() iserrorpage jsp false true exception jsp jsp errorpage List 39 <%@ page iserrorpage= true %> <HTML> http://wwwjava2xmlcom
<BODY> ~!!! <br> <%=exception %><br><br> <% exceptionprintstacktrace(new PrintWriter(out)); %> </BODY> </HTML> jsp errorpage jsp List 39 Resin error, tomcat error error, List39 errorpage jsp jsp ContentType jsp response MIME MIME jsp html text/html Acrobat PDF application/pdf charset charset= encoding <%@ page contenttype= text/html;charset=euc-kr %> NOTE MIME TYPE : Multipurpose Internet Mail Extenstion,, smtp,,,, 1991 SMTP, Nathan Borenstein http://wwwjava2xmlcom
Internet Engineering Task Force, IP 3-1 MIME TYPE application/msword application/octet-stream application/pdf application/vndlotus-notes application/vndms-excel application/vndms-powerpoint application/x-gzip application/x-java-archive application/x-java-serialized-object application/x-java-vm application/zip audio/basic audio/x-wav audio/midi text/css text/html text/xml text/plain image/gif image/jpeg image/png image/x-bitmap video/mpeg binary (PDF) Lotus Notes Gzip JAR Java Java class ZIP au, snd wav midi cascading style sheet html xml text gif jpeg png mpeg page Directive default 3-2 Attribute language import Java Default javalang*, javaxservlet*, javaxservletjsp*, http://wwwjava2xmlcom
extends session buffer autoflush isthreadsafe errorpage iserrorpage info ContentType Jsp12 spec final Draft javaxservlethttp* true 8kb ture true false ( ) text/html;charset=iso-8859-1 12 pageencoding ContentType charset pageencoding taglib Directive jsp (custom tag) jsp TLD ( :Tag Library Descriptor)URItag prefix( ) <%@ taglib uri= taglibraryuri prefix= tagprefix %> uri (prefix), jsp,jspx,javajavax,servlet,sun,sunw jsp, <%@ taglib uri= WEB-INF/classes/tlds/jspace-taglibtld prefix= jspace %> <jspace:hello> </jspace:hello> http://wwwjava2xmlcom
include Directive include jsp (translation-time) <%@ include file= %> include Jsp,, jsp Jsp include <jsp:include> (action) action (request-time) (request) ( ) Request jsp jsp (Directive) Jsp xml (Directive) xml xml XML <jsp:directivedirectivetype attribute= value /> <jsp:directivepage import= javautil* /> <jsp:directivetaglib uri= classes/jspace-tldtld prefix= jspace /> <jsp:directiveinclude file= /jspacejsp /> / xml (Body) http://wwwjava2xmlcom
< />, <tag></tag> page <jsp:directivepage import= javautil*></jsp:directivepage> <tag> (Body)</tag> well-formed xml xml, xml jsp xml (namespace) namespace xml, Html jspxml Scripting Element( ),? Jsp Scripting Elements jsp 1 Expression <%= code %> 2 Scriptlets <% code %> 3 Declarations <! code %> Expression output, Scriptlets _jspservice, Declarations,,,! Jsp //, http://wwwjava2xmlcom
/* */ Jsp <%-- --%>, Html Html <!- - - -> Expression (Expression) jsp Jsp (wrapper) tostring(), tostring() Object ( ) ObjecttoString() tostring() String Vector, int javalanginteger Expression xml <jsp:expression> code </jsp:expression>, 3 3? : (value) (value) <%= (1+3)==5? true : false %> String false, output Html, jsp <a href= http://jspboolpaecom/expressionjsp?id=<%=mathrandom()%> > html expressionjsp id Mathrandom() http://wwwjava2xmlcom
(expression) (;) Scriptlets (, ) Scriptletsxml <jsp:scriptlet> code </jsp:scriptlet> _jspservice Jsp html _jspservice, (expression) _jspservice Declaratin( ) Note : Servlet Life Cycle _jspservice() Life Cycle, init init() init() service() _jspservice() jsp service() jsp service() Http request doget, dopost, doxxx request, (unload) destroy() Lift cycle jsp init() destroy? (Decalration) jspinit(), jspdestory() Declarations http://wwwjava2xmlcom
(declaration) jsp _jspservice <%! Code %> (expression) _jspservice, Life cycle _jspservice isthreadsafe jsp isthreadsafe false SingleThreadModel xml <jsp:declaration> code </jsp:declaration> Action (action), Jsp (Standard) jsp, (custom tag), taglib ( ) <jsp:usebean> <jsp:setproperty> <jsp:getproperty> <jsp:param> <jsp:include> <jsp:forward> <jsp:plugin> usebean, setproperty, getpropertyjavabeans JavaBeans chapter <jsp:param> include, forward, plugin param keyvalue http://wwwjava2xmlcom
<jsp:include> include include (directive) include request time, ( include ), include, include, jsp:include List 39 includefile 01, includefile 02 List 39 <%-- includedfilejsp --%> <%! int i = 0; %> <%-- includefile 01 --%> <%@ include file= includedfilejsp %> <%= i %> <%-- includefile 02 --%> <jsp:include page= includefilejsp flush= true /> <%= i %> include, <jsp:include page= relative url flush= true /> <jsp:include page= relative url flush= true > {<jsp:param /> }* </jsp:include> page, flush http://wwwjava2xmlcom
, true, 11 true 12final Draft <jsp:param> List 310 <%@ page contenttype="text/html;charset=euc-kr" %> <HTML> <BODY> <center><h1> </h1></center><br> <OL> </OL> <LI>include action : <jsp:include page= jspacehtml flush= true /> <LI>include directive <%@ include file= jspacehtml %> </BODY> </HTML> List 311 jspacehtml <B>J</B>space <br>, List 310List 311jspacehtml include List 310 http://wwwjava2xmlcom
Tomcat-321 Jsp charset include Action, List 311, 311html include include (,!) jsp:param <jsp:param> jsp:param jsp:include jsp:forward, jsp:plugin ( 3 ) List 312 paramjsp <HTML> <BODY> http://wwwjava2xmlcom
<center><h1> </h1></center><br> <OL> <LI>include Action : <jsp:include page="jspacejsp" flush="true"> <jsp:param name="para01" value=" " /> </jsp:include> </OL> </BODY> </HTML> List 313 jspacejsp <% String para01 = requestgetparameter("para01"); %> <B>J</B>space <br>, <br>? <%=para01%> List 312List 313include para01 List 313 para01 String http://wwwjava2xmlcom
jsp:param keyvalue jsp:param keyvalue jsp:forward jsp:plugin <jsp:forward> jsp:forward jsp jsp:forward (?), ( ) jsp jsp jsp jsp:forward <jsp:forward page= relativeurl /> <jsp:forward page= relativeurl > {<jsp:param />}* </jsp:forward> jsp:param jsp:include include jsp:forward jsp:param List 314 List 314 <% String despage; if("yes"equalsignorecase(requestgetparameter("destination"))){ despage = "page01jsp"; }else{ despage = "page02jsp"; } %> <jsp:forward page="<%=despage%>" /> destination yespage01jsp page02jsp (Expression) http://wwwjava2xmlcom
NOTE, forward jsp:forward,? javaxservlet RequestDispatcher RequestDispatcher ServletContext getrequestdispatcher() String url = page01jsp ; RequestDispatcher dis = getservletcontext()getrequestdispatcher(url); getservletcontext() javaxservletgenericservlet, javaxservlethttphttpservlet, HttpServlet GenericServletgetServletContext() ( ), getservletcontext() ServletContext ServletContext getrequestdispatcher() RequestDispatcher RequestDispatcher include request (forward) disforward(request, response); request response request (jsp:param ) setattribute() requestsetattribute( key, value ); RequestDispatcher forwardinclude include forward http://wwwjava2xmlcom
jsp jsp servlet <jsp:plugin> jsp, applet, html<applet> <applet> jsp:plugin java12 jdk12 (?) 1 jdk12 Swing, 2 Java 2D 3 Java2 (Collections), EMBED OBJECT (?) jsp:plugin <jsp:plugin type= bean applet code= ObjectCode codebase= ObjectCodebase { align= alignment } { archive= archivelist } { height= height } { hspace= hspace } http://wwwjava2xmlcom
{ jreversion= jreversion } { name= componentname } { vspace= vspace } { width= width } { nspluginurl= url } { iepluginurl= url }> { <jsp:params> <jsp:param name= paramname value= paramvalue />}+ </jsp:params> } { <jsp:fallback> arbitrary_text </jsp:fallback> } </jsp:plugin>, EBNF + * + - type : type appletbean applet bean, bean - code : class Html <applet> jsp:plugin jspxml - height : - Width : HTML<applet> Html tag <applet code= Applet01class width= 200 height= 200 > </applet> jsp:plugin Action <jsp:plugin type= applet code= Applet01class width= 200 height= 200 /> - codebase : http://wwwjava2xmlcom
- align : Html image align - name : Form - archive : jar - vspace : - hspace : - jreversion : JRE (Default11 ) - nsplugin : - ieplugin :, <jsp:plugin> jsp:plug-in jsp:param jsp:params, jsp:param jsp:params, jsp:param jsp:params jsp:param name valuehtml <applet> <param> Html tag <applet code= Applet02class width= 200 height= 200 > <param name= param01 value= value01 > <parma name= param02 value= value02 > </applet> jsp:param / jsp:params Action <jsp:plugin type= applet code= Applet02class width= 200 height= 200 > <jsp:params> <jsp:param name= param01 value= value01 /> <jsp:param name= param02 value= value02 /> </jsp:params> </jsp:plugin> jsp:plugin <jsp:fallback> http://wwwjava2xmlcom
Chapter 3 1 jsp, 2 3 hello jsp jsp jsp jsp, jsp, (Implicit Object) jsp (expression), (scriptlets) (automatically defined variables), (predefined variables), jsp (declaration) ( 3-, ) jsp _jspservice(), _jspservice() _jspservice() 8 http://wwwjava2xmlcom
request request javaxservlethttphttpservletrequest ( http javaxservletservletrequest ) request request (get, post)request http JavaxservlethttpHttpServletRequest API response response javaxservlethttphttpservletresponse ( ) response, API out out javaxservletjspjspwriter javaiowriter PrintWriter, javaioprintwriter out (expression) jsp out outprint( xxx ); <%= xxx %> session javaxservlethttphttpsession jsp,, page (directive) session false session chapter application application javaxservletservletcontext http://wwwjava2xmlcom
Servletcontext (persistence) ServletContext setattribute() application, <% applicationsetattribute( key, value ); %> config javaxservletserveletconfig, pagecontext jsp javaxservletjsppagecontext request (request getrequest() ) page java this Jsp java 8 9? Exception exception page (directive) iserrorpage true jsp javalangthrowable exception iserrorpage (implicit Object) http://wwwjava2xmlcom
[4-1] Request Type scope javaxservletservletrequest javaxservlethttpservletreqeust request response pagecontext session application out config page javaxservletservletresponse javaxservlethttpservletrequest javaxservletjsppagecontext javaxservlethttphttpsession javaxserlvetservletcontext javaxservletjspjspwriter javaxservletservletconfig javalangobject page page session application page page page scope, scope, JavaBeans Beanscope [4-3] scope page scope request (request) page include, forward request session application ( ) http://wwwjava2xmlcom
http://wwwjava2xmlcom