1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu Session 2: Using JSP Tags docx

41 629 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 41
Dung lượng 293 KB

Nội dung

Session 2 Using JSP Tags eACCP2003/Dynamic Pages Using JSP/ Session 2/ 2 of 45 Session Objectives  Describe the various elements of a JavaServer Page  Describe the various JSP Tags in brief eACCP2003/Dynamic Pages Using JSP/ Session 2/ 3 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/ 4 of 45 An Example <HTML> <HEAD><TITLE>MyFirstProgram.jsp</TITLE></HEAD> <BODY> <! MyFirstProgram.JSP > <%@ page import = "java.util.Date" %> <% out.println("Hello there!"); %> <Br> <%= "Current date is " + new Date() %> </BODY> </HTML> Fixed Template data JSP Directive JSP Expression JSP Scriptlet eACCP2003/Dynamic Pages Using JSP/ Session 2/ 5 of 45 What happens under the hood? User Request Web Server/ Servlet Engine JSP Handler Servlet (Page Compilation Servlet) New or modified file? Compile into Servlet Execute Servlet Yes No eACCP2003/Dynamic Pages Using JSP/ Session 2/ 6 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/ 7 of 45 Different Attributes of the Page Directive Attribute Definition language = ”<scriptingLanguage>” 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 = ”<className>" This attribute defines the parent class that the generated servlet will extend. import = ”<importList>" 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 | <size in kb>" This attribute determines whether the output stream is buffered. The default value is 8 kb. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 8 of 45 Different Attributes of the Page Directive – (1) Attribute Definition autoFlush = "true | false" Determines whether the output buffer will be flushed automatically, or whether it will raise an exception when the buffer is full. The default is true. isThreadSafe = "true | false" Specifies whether page can service more than one request at a time. The default is true. info = ”<text>" Specifies information about the JSP, can be accessed by Servlet.getServletInfo(). errorPage = ”<error_URL>" This attribute represents the relative URL to the JSP that will handle exceptions. isErrorPage = "true | false" This attribute states whether or not the JSP is an errorPage. The default is false. contentType = ”<ctinfo>" This attribute represents the MIME type and character set of the response. eACCP2003/Dynamic Pages Using JSP/ Session 2/ 9 of 45 Using page Attributes - An example <%@ page language = "java" import = "java.rmi.*, java.util.*" session = "true" buffer = "12kb" autoFlush = "true" info = "page directive jsp" errorPage = "Error.jsp" isErrorPage = "false" isThreadSafe = "false" %> <HTML> <TITLE> JSP Elements </TITLE> <HEAD> <H1> JSP Elements </H1> </HEAD> <BODY> </BODY> </HTML> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 10 of 45 More on Directives  include directive  Syntax <%@ include file = “relativeURLspec” %>  taglib directive  Syntax <%@ taglib uri = “tagLibraryURI” prefix = “tagPrefix” %> [...]... < /jsp: include> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 24 of 45 Employeeinfo .jsp eACCP2003/Dynamic Pages Using JSP/ Session 2/ 21 of 45 JSP. .. usually JavaBeans        eACCP2003/Dynamic Pages Using JSP/ Session 2/ 19 of 45 JSP Standard Actions – (1)      Associates an instance of a pre-defined JavaBean with a given scope and ID Sets the value of a bean’s property    Accesses...   Enables the JSP engine to dispatch the current request to a static resource, a servlet, or to another JSP at runtime The syntax is as follows: < /jsp: forward> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 26 of 45 Using - An Example s Forward .jsp Using the JSP Forward action... eACCP2003/Dynamic Pages Using JSP/ Session 2/ 31 of 45 } Using - An Example (1) UsePlugin .jsp < /jsp: plugin> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 32 of 45 JSP Standard Actions – (6)  JSP actions have the following characteristics:         These tags are case-sensitive... request.getParameter("employee")); out.println("Title:" + request.getParameter("title")); %> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 28 of 45 Forward .jsp eACCP2003/Dynamic Pages Using JSP/ Session 2/ 22 of 45 Using - An Example This JSP will search for an employee’s... ((request.getParameter("companyID")).equals("1")) {%> < /jsp: forward> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 27 of 45 Using - An Example – (1) MarthaHome .jsp < /jsp: plugin> eACCP2003/Dynamic Pages Using JSP/ Session 2/ 30 of 45 Using - An Example HelloApplet.java public class HelloApplet extends JApplet { public HelloApplet()... Pages Using JSP/ Session 2/ 16 of 45 JSP Scripting Elements – (5) Declarations are the definition of class-level 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 . Session 2 Using JSP Tags eACCP2003/Dynamic Pages Using JSP/ Session 2/ 2 of 45 Session Objectives  Describe the various. Page  Describe the various JSP Tags in brief eACCP2003/Dynamic Pages Using JSP/ Session 2/ 3 of 45 What does a JSP look like?  Three main JSP constructs:  Directives  Allows

Ngày đăng: 25/01/2014, 11:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN