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

Java Server Pages: A Code-Intensive Premium Reference- P22 pptx

10 93 0
Tài liệu đã được kiểm tra trùng lặp

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 167,91 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Exceptions Thrown ƒ java.io.IOException printboolean value Method public void printboolean value throws java.io.IOException This version of the print method prints the passed in boole

Trang 1

Classes

Classes for the javax.servlet package are GenericServlet, ServletInputStream, and

ServletOutputStream Their methods are described in the following sections

GenericServlet Class

The GenericServlet class was created to provide a basic foundation of new servlets It provides default life cycle methods and default implementations of the ServletConfig's methods

GenericServlet() Method

public GenericServlet()

The GenericServlet() method is an empty default constructor GenericServlet() has no

parameters, returns no value, and throws no exceptions

destroy() Method

public void destroy()

The destroy() method is executed when the servlet is removed from the running service It performs any cleanup of resources that were allocated in the init() method destroy() has no parameters, returns no value, and throws no exceptions

getInitParameter() Method

public java.lang.String getInitParameter(

java.lang.String name)

The getInitParameter() method returns a String containing the value of the initialization parameter keyed by the passed in name getInitParameter() throws no exceptions

Parameters

ƒ java.lang.String

Returns

ƒ java.lang.String

getInitParameterNames() Method

public java.util.Enumeration getInitParameterNames()

The getInitParameterNames() method returns an Enumeration containing all of the names for each initialization parameter getInitParameterNames() has no parameters and throws no

exceptions

Returns

ƒ java.util.Enumeration

getServletConfig() Method

public ServletConfig getServletConfig()

The getServletConfig() method returns a ServletConfig object containing any startup

configuration information for this servlet getServletConfig() has no parameters and throws no exceptions

Returns

ƒ ServletConfig

getServletContext() Method

public ServletContext getServletContext()

The getServletContext() method returns a ServletContext object containing information about the servlet's network service getServletContext() has no parameters and throws no exceptions

Returns

ƒ ServletContext

Trang 2

getServletInfo() Method

public java.lang.String getServletInfo()

The getServletInfo() method returns a String containing servlet-specific information about the implementing servlet getServletInfo() has no parameters and throws no exceptions

Returns

ƒ java.lang.String

init(ServletConfig config) Method

public void init(ServletConfig config)

throws ServletException

The init() method marks the beginning of a servlet's life It is called only when the servlet is first loaded, and it must execute successfully before the servlet can service requests The init() method should contain all initialization code for the servlet It returns no value

Parameters

ƒ ServletConfig (encapsulates the servlet's startup configuration and initialization parameters)

Exceptions Thrown

ƒ ServletException

init() Method

public void init()

throws ServletException

This parameterless implementation of the init() method is provided only for convenience It prevents a derived servlet from having to store the ServletConfig object init() has no parameters and returns

no value

Exceptions Thrown

ƒ ServletException

log(java.lang.String message) Method

public void log(java.lang.String message)

The log() method takes the passed in message and the name of the servlet and writes them to a log file The location of the log is server specific log() returns no value and throws no exceptions

Parameters

ƒ java.lang.String

log(java.lang.String message, java.lang.Throwable t) Method

public void log(java.lang.String message,

java.lang.Throwable t)

This log() method takes the passed in message and Throwable object and logs the message with a stack trace from the Throwable object log() returns no value and throws no exceptions

Parameters

ƒ java.lang.String

ƒ java.lang.Throwable

service() Method

public void service(ServletRequest request,

ServletResponse response)

throws ServletException,

java.io.IOException

Trang 3

The service() method defines the servlet's entry point for servicing requests It can be executed only after the servlet's init() method has executed successfully The service() method is the life cycle method executed for every incoming request It returns no value

Parameters

ƒ ServletRequest

ƒ ServletResponse

Exceptions Thrown

ƒ ServletException

ƒ java.io.IOException

ServletInputStream Class

The ServletInputStream is an abstract class defined for servlet writers to get data from the client It is meant to be implemented by a network services writer This class has two methods

ServletInputStream() Method

protected ServletInputStream()

The ServletInputStream() method is the empty default constructor It has no parameters, returns no value, and throws no exceptions

readLine() Method

public void readLine(byte[] b,

int off,

int len)

throws java.io.IOException

The readLine() method reads the len of bytes into the passed in byte array b, starting at position off

If the character '\n' is encountered, then no more bytes are read in readLine() returns no value

Parameters

ƒ byte[]

ƒ int

ƒ int

Exceptions Thrown

ƒ java.io.IOException

ServletOutputStream Class

The ServletOutputStream class is used to write responses back to the client It is an abstract class that is implemented by the network services implementor To access the ServletOutputStream, you must call the ServletResponse's getOutputStream() method The class has several methods

ServletOutputStream() Method

public ServletOutputStream()

throws java.io.IOException

The ServletOutputStream() method is the empty default constructor It has no parameters and returns no value

Exceptions Thrown

ƒ java.io.IOException

print(boolean value) Method

public void print(boolean value)

throws java.io.IOException

This version of the print() method prints the passed in boolean value to the output stream

Trang 4

Parameters

ƒ boolean

Note The print() method always throws a java.io.IOException exception For all print values, the

print() method returns no value

print(char value) Method

public void print(char value)

throws java.io.IOException

This version of the print() method prints the passed in char value to the output stream

Parameters

ƒ char

print(double value) Method

public void print(double value)

throws java.io.IOException

This version of the print() method prints the passed in double value to the output stream

Parameters

ƒ double

print(float value) Method

public void print(float value)

throws java.io.IOException

This version of the print() method prints the passed in float value to the output stream

Parameters

ƒ float

print(int value) Method

public void print(int value)

throws java.io.IOException

This version of the print() method prints the passed in int value to the output stream

Parameters

ƒ int

print(long value) Method

public void print(long value)

throws java.io.IOException

This version of the print() method prints the passed in long value to the output stream

Parameters

ƒ long

print(java.lang.String value) Method

public void print(java.lang.String value)

throws java.io.IOException

This version of the print() method prints the passed in String value to the output stream

Parameters

ƒ java.lang.String

Trang 5

println() Method

public void println()

throws java.io.IOException

This version of the println() method prints CRLF to the output stream and has no parameters

Note The println() method always throws a java.io.IOException exception For all print values, the

println() method returns no value

println(java.lang.String value) Method

public void println(java.lang.String value)

throws java.io.IOException

This version of the println() method prints the passed in String value to the output stream, followed

by a CRLF

Parameters

ƒ java.lang.String

println(boolean value) Method

public void println(boolean value)

throws java.io.IOException

This version of the println() method prints the passed in boolean value to the output stream, followed

by a CRLF

Parameters

ƒ boolean

println(char value) Method

public void println(char value)

throws java.io.IOException

This version of the println() method prints the passed in char value to the output stream, followed by

a CRLF

Parameters

ƒ char

println(int value) Method

public void println(int value)

throws java.io.IOException

This version of the println() method prints the passed in int value to the output stream, followed by a CRLF

Parameters

ƒ int

println(long value) Method

public void println(long value)

throws java.io.IOException

This version of the println() method prints the passed in long value to the output stream, followed by

a CRLF

Parameters

ƒ long

println(float value) Method

public void println(float value)

Trang 6

throws java.io.IOException

This version of the println() method prints the passed in float value to the output stream, followed by

a CRLF

Parameters

ƒ float

println(double value) Method

public void println(double value)

throws java.io.IOException

This version of the println() method prints the passed in double value to the output stream, followed

by a CRLF

Parameters

ƒ double

Classes

Classes for the javax.servlet package are GenericServlet, ServletInputStream, and

ServletOutputStream Their methods are described in the following sections

GenericServlet Class

The GenericServlet class was created to provide a basic foundation of new servlets It provides default life cycle methods and default implementations of the ServletConfig's methods

GenericServlet() Method

public GenericServlet()

The GenericServlet() method is an empty default constructor GenericServlet() has no

parameters, returns no value, and throws no exceptions

destroy() Method

public void destroy()

The destroy() method is executed when the servlet is removed from the running service It performs any cleanup of resources that were allocated in the init() method destroy() has no parameters, returns no value, and throws no exceptions

getInitParameter() Method

public java.lang.String getInitParameter(

java.lang.String name)

The getInitParameter() method returns a String containing the value of the initialization parameter keyed by the passed in name getInitParameter() throws no exceptions

Parameters

ƒ java.lang.String

Returns

ƒ java.lang.String

getInitParameterNames() Method

public java.util.Enumeration getInitParameterNames()

The getInitParameterNames() method returns an Enumeration containing all of the names for each initialization parameter getInitParameterNames() has no parameters and throws no

exceptions

Returns

ƒ java.util.Enumeration

Trang 7

getServletConfig() Method

public ServletConfig getServletConfig()

The getServletConfig() method returns a ServletConfig object containing any startup

configuration information for this servlet getServletConfig() has no parameters and throws no exceptions

Returns

ƒ ServletConfig

getServletContext() Method

public ServletContext getServletContext()

The getServletContext() method returns a ServletContext object containing information about the servlet's network service getServletContext() has no parameters and throws no exceptions

Returns

ƒ ServletContext

getServletInfo() Method

public java.lang.String getServletInfo()

The getServletInfo() method returns a String containing servlet-specific information about the implementing servlet getServletInfo() has no parameters and throws no exceptions

Returns

ƒ java.lang.String

init(ServletConfig config) Method

public void init(ServletConfig config)

throws ServletException

The init() method marks the beginning of a servlet's life It is called only when the servlet is first loaded, and it must execute successfully before the servlet can service requests The init() method should contain all initialization code for the servlet It returns no value

Parameters

ƒ ServletConfig (encapsulates the servlet's startup configuration and initialization parameters)

Exceptions Thrown

ƒ ServletException

init() Method

public void init()

throws ServletException

This parameterless implementation of the init() method is provided only for convenience It prevents a derived servlet from having to store the ServletConfig object init() has no parameters and returns

no value

Exceptions Thrown

ƒ ServletException

log(java.lang.String message) Method

public void log(java.lang.String message)

The log() method takes the passed in message and the name of the servlet and writes them to a log file The location of the log is server specific log() returns no value and throws no exceptions

Parameters

ƒ java.lang.String

Trang 8

log(java.lang.String message, java.lang.Throwable t) Method

public void log(java.lang.String message,

java.lang.Throwable t)

This log() method takes the passed in message and Throwable object and logs the message with a stack trace from the Throwable object log() returns no value and throws no exceptions

Parameters

ƒ java.lang.String

ƒ java.lang.Throwable

service() Method

public void service(ServletRequest request,

ServletResponse response)

throws ServletException,

java.io.IOException

The service() method defines the servlet's entry point for servicing requests It can be executed only after the servlet's init() method has executed successfully The service() method is the life cycle method executed for every incoming request It returns no value

Parameters

ƒ ServletRequest

ƒ ServletResponse

Exceptions Thrown

ƒ ServletException

ƒ java.io.IOException

ServletInputStream Class

The ServletInputStream is an abstract class defined for servlet writers to get data from the client It is meant to be implemented by a network services writer This class has two methods

ServletInputStream() Method

protected ServletInputStream()

The ServletInputStream() method is the empty default constructor It has no parameters, returns no value, and throws no exceptions

readLine() Method

public void readLine(byte[] b,

int off,

int len)

throws java.io.IOException

The readLine() method reads the len of bytes into the passed in byte array b, starting at position off

If the character '\n' is encountered, then no more bytes are read in readLine() returns no value

Parameters

ƒ byte[]

ƒ int

ƒ int

Exceptions Thrown

ƒ java.io.IOException

Trang 9

ServletOutputStream Class

The ServletOutputStream class is used to write responses back to the client It is an abstract class that is implemented by the network services implementor To access the ServletOutputStream, you must call the ServletResponse's getOutputStream() method The class has several methods

ServletOutputStream() Method

public ServletOutputStream()

throws java.io.IOException

The ServletOutputStream() method is the empty default constructor It has no parameters and returns no value

Exceptions Thrown

ƒ java.io.IOException

print(boolean value) Method

public void print(boolean value)

throws java.io.IOException

This version of the print() method prints the passed in boolean value to the output stream

Parameters

ƒ boolean

Note The print() method always throws a java.io.IOException exception For all print values, the

print() method returns no value

print(char value) Method

public void print(char value)

throws java.io.IOException

This version of the print() method prints the passed in char value to the output stream

Parameters

ƒ char

print(double value) Method

public void print(double value)

throws java.io.IOException

This version of the print() method prints the passed in double value to the output stream

Parameters

ƒ double

print(float value) Method

public void print(float value)

throws java.io.IOException

This version of the print() method prints the passed in float value to the output stream

Parameters

ƒ float

print(int value) Method

public void print(int value)

throws java.io.IOException

This version of the print() method prints the passed in int value to the output stream

Parameters

ƒ int

Trang 10

print(long value) Method

public void print(long value)

throws java.io.IOException

This version of the print() method prints the passed in long value to the output stream

Parameters

ƒ long

print(java.lang.String value) Method

public void print(java.lang.String value)

throws java.io.IOException

This version of the print() method prints the passed in String value to the output stream

Parameters

ƒ java.lang.String

println() Method

public void println()

throws java.io.IOException

This version of the println() method prints CRLF to the output stream and has no parameters

Note The println() method always throws a java.io.IOException exception For all print values, the

println() method returns no value

println(java.lang.String value) Method

public void println(java.lang.String value)

throws java.io.IOException

This version of the println() method prints the passed in String value to the output stream, followed

by a CRLF

Parameters

ƒ java.lang.String

println(boolean value) Method

public void println(boolean value)

throws java.io.IOException

This version of the println() method prints the passed in boolean value to the output stream, followed

by a CRLF

Parameters

ƒ boolean

println(char value) Method

public void println(char value)

throws java.io.IOException

This version of the println() method prints the passed in char value to the output stream, followed by

a CRLF

Parameters

ƒ char

println(int value) Method

public void println(int value)

throws java.io.IOException

Ngày đăng: 03/07/2014, 06:20