YOMEDIA
ADSENSE
Session 2: Using JSP Tags
175
lượt xem 53
download
lượt xem 53
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
Session Objectives Describe the various elements of a JavaServer Page Describe the various JSP Tags in brief
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Session 2: Using JSP Tags
- Session 2 Using JSP Tags
- Session Objectives Describe the various elements of a JavaServer Page Describe the various JSP Tags in brief eACCP2003/Dynamic Pages Using JSP/ Session 2/ 2 of 45
- What does a JSP look like? Three main JSP constructs: Directives Allows one to control structure of the servlet Scripting Elements Used to include Java code Actions Specific tags that affect the runtime behavior of the JSPs eACCP2003/Dynamic Pages Using JSP/ Session 2/ 3 of 45
- Fixed Template An Example data MyFirstProgram.jsp JSP Directive JSP Scriptlet JSP Expression eACCP2003/Dynamic Pages Using JSP/ Session 2/ 4 of 45
- What happens under the hood? User Web Server/ Request Servlet Engine No JSP Handler Servlet New or (Page Compilation Servlet) modified file? Yes Compile into Execute Servlet Servlet eACCP2003/Dynamic Pages Using JSP/ Session 2/ 5 of 45
- Various Elements in a JSP Directives page Defines information that will be globally available for a JSP include Used to insert text and code at JSP translation time taglib Defines a mechanism for extending the current set of JSP tags eACCP2003/Dynamic Pages Using JSP/ Session 2/ 6 of 45
- Different Attributes of the Page Directive Attribute Definition language = This attribute tells the server about the language to be ”” used to complete the JSP file. At present, Java is the only language that can be used. extends = This attribute defines the parent class that the generated ”" servlet will extend. import = This attribute defines the list of packages that will be ”" available to this JSP. However, a comma must separate each package. session = "true | false" This attribute determines whether the session data will be available to this page. The default is true. buffer = "none | " buffered. The default value is 8 kb. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 7 of 45
- Different Attributes of the Page Directive – (1) Attribute Definition autoFlush = "true | Determines whether the output buffer will be flushed false" automatically, or whether it will raise an exception when the buffer is full. The default is true. isThreadSafe = "true Specifies whether page can service more than one | false" request at a time. The default is true. info = ”" Specifies information about the JSP, can be accessed by Servlet.getServletInfo(). errorPage = This attribute represents the relative URL to the JSP ”" that will handle exceptions. isErrorPage = "true | This attribute states whether or not the JSP is an false" errorPage. The default is false. contentType = This attribute represents the MIME type and ”" character set of the response. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 8 of 45
- Using page Attributes An example JSP Elements JSP Elements eACCP2003/Dynamic Pages Using JSP/ Session 2/ 9 of 45
- More on Directives include directive Syntax taglib directive Syntax eACCP2003/Dynamic Pages Using JSP/ Session 2/ 10 of 45
- Some Important Points While using directives, remember the following: Directives are messages to the JSP container, that is, the JSP engine Directives do not store any results in the output buffer Directives are processed when the JSP is initialized eACCP2003/Dynamic Pages Using JSP/ Session 2/ 11 of 45
- JSP Scripting Elements Scripting is a mechanism for embedding code fragments directly in an HTML page. The following three scripting elements are involved in JSP scripting: Expressions Scriptlets Declarations eACCP2003/Dynamic Pages Using JSP/ Session 2/ 12 of 45
- JSP Scripting Elements – (1) Expressions are evaluated to produce a java.lang.String type result. Syntax: Evaluated to Example: produce 4 2 + 2 equals eACCP2003/Dynamic Pages Using JSP/ Session 2/ 13 of 45
- JSP Scripting Elements – (2) Scriptlets contain code that is valid for the language specified in the language directive. Java is the only language that is presently available. Syntax: Example: Scriptlet eACCP2003/Dynamic Pages Using JSP/ Session 2/ 14 of 45
- JSP Scripting Elements – (3) Like expressions, scriptlets also have access to implicit variables. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 15 of 45
- JSP Scripting Elements – (4) Scriptlets do not need complete Java statements, and open blocks can affect the static HTML outside the scriptlets. 0.5) { %> Have a happy birthday!! Have a nice day!! eACCP2003/Dynamic Pages Using JSP/ Session 2/ 16 of 45
- JSP Scripting Elements – (5) Declarations are the definition of classlevel variables and methods that are used in a JSP. Syntax: Example: Declaration This page has been accessed time(s) since the server was rebooted. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 17 of 45
- JSP Scripting Elements – (6) Points to remember about declarations: Declarations do not produce any printable results. Variables are initialized when the JSP is initialized. Such variables are available to other declarations, expressions, and scriptlets. Variables created through declarations become instance variables. Simultaneous users of the JSP share the same instance of the variable. Class variables and functions can be declared in a declaration block. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 18 of 45
- JSP Standard Actions A JSP action directive provides an easy method to encapsulate common tasks. These typically create or act on objects, usually JavaBeans. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 19 of 45
- JSP Standard Actions – (1) Associates an instance of a predefined JavaBean with a given scope and ID Sets the value of a bean’s property Accesses the value of the specified property of a bean instance Converts it to a java.lang.String object Places it in the implicit out object eACCP2003/Dynamic Pages Using JSP/ Session 2/ 20 of 45
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn