Summary

 < Free Open Study > 



In this chapter we introduced you to the Servlet 2.3 API, and focused upon the javax.servlet package.

We examined the API structure and design and then looked at the classes and interfaces of the javax.servlet package in detail, building some example servlets that made use of them along the way. We looked at the Servlet interface and the GenericServlet class that implements this interface, as well as the servlet lifecycle.

The request-response cycle was then covered, and we discussed the relevant ServletRequest and ServletResponse interfaces. We also reviewed their wrapper classes - the ServletRequestWrapper and ServletResponseWrapper.

We examined the design and use of the servlet input and output classes ServletInputStream and ServletOutputStream, followed by a look at servlet-container communication through the ServletConfig and ServletContext interfaces.

This was followed by a look at the SingleThreadModel and the RequestDispatcher interfaces. We concluded our look at the javax.servlet package by examining the two servlet exception classes ServletException and UnavailableException.

We concluded the chapter by developing a small Personal Portal application, in order to implement and demonstrate the use of the API classes, interfaces, and methods that we have learnt so far. We explained how a web application like this can be run in the Catalina servlet container within the Tomcat web server.

In the next chapter we will examine HTTP servlets and the javax.servlet.http package in detail, and develop an example HTTP client-server (servlet) application.

A

AppendRow() method

  • HTMLTable utility class, 17

appendTitleRow() method

  • HTMLTable utility class, 17

attribute reference

  • getAttribute() method, 41

attributeAdded() method

  • ServletContextAttributeListener interface, 49

attributeRemoved() method

  • ServletContextAttributeListener interface, 49

attributeReplaced() method

  • ServletContextAttributeListener interface, 49

attributes

  • setting and accessing requests, 22

B

BasicServlet, GenericServlet class

  • creating, 10

buffer sizing

  • container requests, 33

  • exception thrown, 33

  • getBufferSize/set~() methods, 31

BufferedReader object, java.io

  • reading body of request, 26

buffering

  • !see also output buffering, 32

  • output, ServletResponse interface, 31

C

change notification

  • ServletContextAttributeEvent class, 4

  • ServletContextEvent class, 4

character sets

  • getCharacterEncoding() method, 30

  • web site, 25

checking security

  • getRequestTable() method, 24

classes

  • exception classes, 5

  • GenericServlet abstract class, 4, 8

  • GenericServlet class, 4

  • InputStream class, java.io, 34

  • OutputStream class, java.io, 34

  • PrintWriter class, java.io, 36

  • RequestResponseServlet class, 14

  • ServletContextAttributeEvent class, 4, 48

  • ServletContextEvent class, 4, 48

  • ServletException class, 4, 55

  • ServletInputStream class, 4, 34

  • ServletOutputStream class, 4, 34

  • ServletRequestWrapper class, 4

  • ServletResponseWrapper class, 4

  • UnavailableException class, 5, 55

  • wrapper classes, 4

client information

  • obtaining, getRemoteAddr() method, 26

  • obtaining, getRemoteHost() method, 26

  • retrieving, getRequestTable() method, 27

connection security

  • isSecure() method, 24

constructors

  • ServletException() constructors, 55

  • UnavailableException() constructors, 55

container requests

  • buffer sizing, 33

containers

  • servlet container communication, 37

ContainerServlet class

  • example, 38

  • extends GenericServlet class, 37

content length

  • setContentLength() method, 29

contextDestroyed() method

  • ServletContextListener interface, 49

contextInitialized() method

  • ServletContextListener interface, 49

customizing response to client

  • Locale object, 25

D

DataMapping Interface

  • personalPortal web application, 61, 65, 70

debugging

  • log() utility method, 9

destroy() method

  • servlet lifecycle defined, 6

  • servlet lifecycle management, 7

Dispatching interface

  • RequestDispatcherServlet class, 52

  • RequestDispatcherServlet example, 51

Domain Name Servers (DNS)

  • IP addresses, 27

E

environment methods

  • !see also methods.

  • getInitParameter() method, ServletContext object, 9

  • getInitParameterNames() method, ServletContext object, 9

  • getServletConfig() method, 8

  • getServletName() method, 8

  • servlets, 8

event classes

  • ServletContextAttributeEvent class, 48

  • ServletContextEvent class, 48

exception classes

  • ServletException class, 4

  • UnavailableException class, 5

exception handling process, 55

exceptions

  • servlet lifecycle defined, 6

F

FAQ HTML page

  • personalPortal web application, 71

filter unavailability

  • UnavailableException class, 5

flushBuffer() method

  • output buffering, 32

forward() method

  • RequestDispatcher interface, 50

G

GenericServlet abstract class, 8-13

  • BasicServlet, creating, 10

  • BasicServlet, lifecycle methods, 10

  • destroy() method, 8

  • init() method, 8

  • lifecycle methods, 8

  • protocol independent servlets, 4

  • service() method, 4, 8

  • Servlet interface, 5

  • ServletConfig interface, implements, 39

getAccessData() method

  • personalPortal web application, 70

getAttribute() method

  • attribute reference, 41

  • request header information, 22

getAttributeNames() method

  • request header information, 21

  • ServletContext attributes, accessing, 41

getBufferSize() method

  • output buffering, 31

getCharacterEncoding() method

  • internationalization, 25

  • returns character set, 30

getClosePage() method

  • personalPortal web application, 63

getConfigTable() method

  • ServletConfig object reference, 40

getContentLength() method

  • request header information, obtaining, 20

getContentType() method

  • request header information, obtaining, 21

getContext() method

  • server environment information, 44

getContextTable() method

  • general servlet information, 43

  • server environment information, 45

  • server information, 44

  • ServletContext attributes, 42

getError() method

  • personalPortal web application, 63

getForm() method

  • RequestDispatcherServlet example, 54

getInitParameter() method

  • environment method, 9

  • initialization parameter names, 43

  • retrieving information, ServletConfig, 40

getInitParameterNames() method

  • environment method, 9

  • initialization parameters, 43

  • retrieving information, ServletConfig, 40

getInputStream() method

  • reading from request, 26

getLocale() method

  • finding locale used in request, 25

  • internationalization, 24

  • using internationalization in response, 29

getLocales() method

  • internationalization, 25

getMajorVersion() method

  • server information, 43

getMimeType() method

  • server environment information, 45

getMinorVersion() method

  • server information, 43

getName() method

  • ServletContextAttributeEvent class, 48

getNamedDispatcher() method

  • RequestDispatcher object, 44

getNewsPage() method

  • personalPortal web application, 70

getOpenPage() method

  • personalPortal web application, 63

getOutputStream() method

  • returning data in response, 31

getPageTitle() method

  • RequestDispatcherServlet example, 53

getParameter() method

  • ServletRequest interface, 19

getParameterMap() method

  • ServletRequest interface, 20

getParameterNames() method

  • ServletRequest interface, 19

getParameterValues() method

  • ServletRequest interface, 19

getProtocol() method

  • request header information, obtaining, 21

getReader() method

  • reading body of request, 26

getRealPath() method

  • server environment information, 44

getRemoteAddr() method

  • obtaining client information, 26

getRemoteHost() method

  • obtaining client information, 26

getRequestDispatcher() method

  • creating a RequestDispatcher, 28

  • RequestDispatcher object, 44

getRequestTable() method

  • adding client IP address, 27

  • checking security, 24

  • internationalization, 25

  • RequestResponseServlet class, 18

  • retrieving client information, 27

  • retrieving request path, 23

  • ServletRequest interface, 20

  • setting and accessing request attributes, 22

getResource() method

  • server environment information, 45

getResourceAsStream() method

  • server environment information, 45

getResourcePaths() method

  • server environment information, 45

getResponseTable() method

  • construction of, example, 30

  • internationalization, using in, 30

  • output buffering, 32

  • RequestResponseServlet class, 18

getRootCause() method

  • ServletException class, 55

getScheme() method

  • path information, 23

getServerInfo() method

  • server information, 44

getServerName() method

  • host server name, obtaining, 23

getServerPort() method

  • host server name, obtaining, 23

getServletConfig() method

  • environment method, 8

  • Servlet interface, 6

  • ServletConfig object reference, 40

getServletContext() method

  • Servlet interface, 3

  • ServletContext object reference, 40

  • ServletContextEvent class, 48

getServletContextName() method

  • web application name, 43

getServletInfo() method

  • obtaining servlet information, 7

getServletName() method

  • BasicServlet example, GenericServlet class, 11

  • environment method, 8

  • GenericServlet class, 40

getUnavailableSeconds() method

  • UnavailableException class, 55

getValue() method

  • ServletContextAttributeEvent class, 48

getWriter() method

  • BasicServlet example, GenericServlet class, 11

  • returning data in response, 31

H

HTMLPortal class

  • personalPortal web application, 62

HTMLPortal object

  • personalPortal web application, 66

HTMLTable utility class

  • appendRow() method, 17

  • appendTitleRow() method, 17

  • HTML table, 2 column, 16

  • RequestResponseServlet class, used by, 16

  • toString() method, 18

  • toStringBuffer() method, 18

I

I/O streams

  • PrintWriter class, java.io, 36

  • Servlet 2.3 API, 34

  • ServletInputStream class, 4, 34

  • ServletOutputStream class, 4, 34

IllegalStateException

  • calling getReader() and getInputStream(), 26

include() method

  • personalPortal web application, 66

  • RequestDispatcher interface, 50

  • RequestDispatcherServlet example, 53

init() method

  • BasicServlet example, GenericServlet class, 11

  • GenericServlet abstract class, 8

  • personalPortal web application, 66

  • RequestDispatcherServlet example, 53

  • servlet lifecycle defined, 6

  • superclass method call eliminated, 8

initialization parameter names

  • getInitParameter() method, 43

  • getInitParameterNames() method, 43

  • retrieving information, ServletConfig, 40

InputStream class, java.io

  • ServletOutputStream class, 34

InputStream object

  • getResourceAsStream() method, 45

interfaces

  • RequestDispatcher interface, 3, 50

  • Servlet interface, 2, 3

  • ServletConfig interface, 37, 39

  • ServletContext interface, 37, 41

  • ServletContextAttributeListener interface, 49

  • ServletContextListener interface, 3, 49

  • ServletRequest interface, 14

  • SingleThreadModel interface, 3, 49

internationalization

  • getCharacterEncoding() method, 25

  • getLocale() method, 24, 25

  • getLocales() method, 25

  • getRequestTable() method, 25

  • request processing, 24

  • setCharacterEncoding() method, 25

  • using in getResponseTable(), 30

  • using in response, 29

IOException class

  • exception handling process, 55

IP addresses

  • Domain Name Servers (DNS), 27

isCommitted() method

  • output buffering, 31

  • RequestDispatcherServlet example, 53

isEmailOK() method

  • personalPortal web application, 68

isPermanent() method

  • UnavailableException class, 56

isSecure() method

  • connection security, 24

J

Java Servlet 2.3 API see p.Servlet 2.3 API.

javax.servlet package, 1

  • classes, list of, 3

  • exception classes, list of, 4

  • interfaces, list of, 2

  • Servlet interface, 2

L

lifecycle methods

  • Servlet interface, 5

Locale object

  • extracting from response object, 30

Locale object/class

  • customizing response to client, 25

  • web site, 25

locales

  • finding locale used in request, 25

  • internationalization, 24

log() utility method

  • debugging, 9

  • live environment, a warning, 9

log() utility methods

  • ServletContext interface, 47

M

methods

  • appendRow() method, 17

  • appendTitleRow() method, 17

  • attributeAdded() method, 49

  • attributeRemoved() method, 49

  • attributeReplaced() method, 49

  • contextDestroyed() method, 49

  • contextInitialized() method, 49

  • destroy() method, 5

  • environment methods, 8

  • flushBuffer() method, 32

  • forward() method, 50

  • getAttribute() method, 22, 41

  • getAttributeNames() method, 21, 41

  • getBufferSize() method, 31

  • getCharacterEncoding() method, 25, 30

  • getConfigTable() method, 40

  • getContentLength() method, 20

  • getContentType() method, 21

  • getContext() method, 44

  • getContextTable() method, 42, 43, 44, 45

  • getInitParameter() method, 9, 40, 43

  • getInitParameterNames() method, 9, 40, 43

  • getInputStream() method, 26

  • getLocale() method, 24, 25, 29

  • getLocales() method, 25

  • getMajorVersion() method, 43

  • getMimeType() method, 45

  • getMinorVersion() method, 43

  • getName() method, 48

  • getNamedDispatcher() method, 44

  • getOutputStream() method, 31

  • getParameter() method, 19

  • getParameterMap() method, 20

  • getParameterNames() method, 19

  • getParameterValues() method, 19

  • getProtocol() method, 21

  • getReader() method, 26

  • getRealPath() method, 44

  • getRemoteAddr() method, 26

  • getRemoteHost() method, 26

  • getRequestDispatcher() method, 28, 44

  • getRequestTable() method, 18, 22, 23, 24, 25, 27

  • getResource() method, 45

  • getResourceAsStream() method, 45

  • getResourcePaths() method, 45

  • getResponseTable() method, 18, 30, 32

  • getRootCause() method, 55

  • getScheme() method, 23

  • getServerInfo() method, 44

  • getServerName() method, 23

  • getServerPort() method, 23

  • getServletConfig() method, 6, 8, 40

  • getServletContext() method, 3, 40, 48

  • getServletContextName() method, 43

  • getServletInfo() method, 7

  • getServletName() method, 8, 40

  • getUnavailableSeconds() method, 56

  • getValue() method, 48

  • getWriter() method, 31

  • include() method, 50

  • init() method, 5

  • isCommitted() method, 32

  • isPermanent() method, 56

  • isSecure() method, 24

  • lifecycle methods, 5

  • log() method, 9

  • log() methods, 47

  • removeAttribute() method, 22, 42

  • reset() method, 32

  • resetBuffer() method, 32

  • service() method, 4, 5

  • setAttribute() method, 22, 42

  • setBufferSize() method, 31

  • setCharacterEncoding() method, 25

  • setContentLength() method, 29

  • setContentType() method, 29

  • setLocale() method, 29

  • storeAttribute() method, 22

  • toString() method, 18

  • toStringBuffer() method, 18

  • utility methods, 9

MIME types

  • getCharacterEncoding() method, 30

  • method for setting, 29

  • setContentType() method, 29

N

NewsServlet class

  • personalPortal web application, 69

O

objects

  • BufferedReader object, java.io, 26

output buffering

  • flushBuffer() method, 32

  • getBufferSize() method, 31

  • getResponseTable() method, 32

  • isCommitted() method, 31

  • reset() method, 32

  • resetBuffer() method, 32

  • ServletResponse interface, 31

  • setBufferSize() method, 31

OutputStream class, java.io

  • ServletOutputStream class, 34

overriding

  • destroy() method, 8

P

packages

  • javax.servlet package, 1

parameters

  • names and values, ServletRequest interface, 19

path information

  • getRequestTable() method, 23

  • getScheme() method, 23

  • retrieving request path, 23

  • ServletRequest interface, 23

personalPortal web application, 56-71

  • DataMapping Interface, 61, 65

  • FAQ HTML page, 71

  • getXXX() methods, 63

  • HTMLPortal class, 62

  • NewsServlet class, 69

  • PortalServlet class, 65

  • prepareXXX() methods, 63

  • SubscribeServlet class, 67

PortalServlet class

  • personalPortal web application, 65

prepareMenu() method

  • personalPortal web application, 63, 64

prepareOpenPage() method

  • personalPortal web application, 63

preparePrintLink() method

  • personalPortal web application, 63, 65

preparePrintOpenPage() method

  • personalPortal web application, 64

prepareUrl() method

  • personalPortal web application, 65

print/~ln() methods

  • overloaded variants, 36

  • ServletOutputStream class, 36

printForm() method

  • personalPortal web application, 69

PrintWriter class, java.io

  • I/O streams, 36

  • web site, 36

PrintWriter object

  • getWriter() method, 31

processSubscription() method

  • personalPortal web application, 68

R

references to web sites

  • character sets, web site, 25

  • Locale object/class information, 25

  • PrintWriter class, java.io, 36

removeAttribute() method

  • request header information, 22

  • ServletContext attributes, remove from, 42

request header information, ServletRequest

  • interface

  • accessing, 20

  • getAttribute() method, 22

  • getAttributeNames() method, 21

  • getContentLength() method, 20

  • getContentType() method, 21

  • getProtocol() method, 21

  • removeAttribute() method, 22

  • setAttribute() method, 22

  • storeAttribute() method, 22

request object

  • reading from request, 26

RequestDispatcher interface

  • client requests, 3

  • forward() method, 50

  • forwarding requests, 50

  • include() method, 50

  • RequestDispatcherServlet example, 50

RequestDispatcher object

  • creating, getRequestDispatcher() method, 28

  • getNamedDispatcher() method, 44

  • getRequestDispatcher() method, 44

  • personalPortal web application, 66

RequestDispatcherServlet class

  • RequestDispatcherServlet example, 52

RequestDispatcherServlet example

  • RequestDispatcher interface, 50

request-response cycle

  • interfaces and wrapper classes, 14

  • servlets, 14

RequestResponseServlet class

  • implementing, 14

  • service() method, 18

  • uses HTMLTable utility class, 16

requests

  • forwarding, RequestDispatcher interface, 50

  • reading, getInputStream() method, 26

  • reading, getReader() method, 26

  • reading, reading body of request, 26

  • setting and accessing attributes, 22

reset() method

  • output buffering, 32

resetBuffer() method

  • output buffering, 32

response

  • returning data, getOutputStream() method, 31

  • returning data, getWriter() method, 31

  • returning data, ServletResponse interface, 31

response object

  • extracting Locale object from, 30

S

security

  • checking security, 24

  • connection security, 24

server environment information

  • getContext() method, 44

  • getContextTable() method, 45

  • getMimeType() method, 45

  • getRealPath() method, 44

  • getResource() method, 45

  • getResourceAsStream() method, 45

  • getResourcePaths() method, 45

server information

  • getContextTable() method, 44

  • getMajorVersion() method, 43

  • getMinorVersion() method, 43

  • getServerInfo() method, 44

  • getServerName() method, 23

  • getServerPort() method, 23

  • obtaining host name, 23

  • obtaining port no., 23

service() method

  • BasicServlet example, GenericServlet class, 10

  • ContainerServlet class, 39

  • GenericServlet abstract class, 4, 8

  • personalPortal web application, 66, 67, 70

  • RequestResponseServlet class, 18

  • servlet lifecycle defined, 6

  • servlet lifecycle management, 7

  • servlet threading issues, 7

  • threading, 49

Servlet 2.3 API, 1

  • IO stream wrapper classes, 26

  • servlet exception classes, 54

servlet container

  • managing servlet lifecycle, 5

servlet container communication, 37-49

  • ServletConfig interface, 39

  • ServletContext interface, 41

  • ServletContext lifecycle classes, 48

servlet exception classes

  • Servlet 2.3 API, 54

  • ServletException class, 55

  • UnavailableException class, 55

Servlet interface, 5-7

  • GenericServlet abstract class, 8

  • GenericServlet class, 5

  • getServletConfig() method, 6

  • getServletInfo() method, 7

  • lifecycle methods, 5

  • servlet life cycle, 3

servlet lifecycle

  • defined, 6

  • management, 7

servlet unavailability

  • UnavailableException class, 5

ServletConfig interface

  • GenericServlet class implements, 39

  • getInitParameter() method, 40

  • getInitParameterNames() method, 40

  • retrieving information, 40

  • servlet container communication, 37, 39

ServletConfig object

  • getConfigTable() method reference, 40

  • getServletConfig() method reference, 40

ServletContext attributes

  • accessing, getAttributeNames() method, 41

  • getContextTable() method, 42

  • remove attributes, 42

  • removeAttribute() method, 42

  • setAttribute() method, 42

ServletContext interface

  • log() methods, 47

  • server environment information, 44

  • server information, 43

  • servlet container communication, 37, 41

  • servlet information, 43

  • ServletContext attributes, accessing, 41

  • utility methods, 47

ServletContext lifecycle classes

  • servlet container communication, 48

  • ServletContextAttributeEvent class, 48

  • ServletContextAttributeListener interface, 49

  • ServletContextEvent class, 48

  • ServletContextListener interface, 49

ServletContext object

  • getContext() method reference, 44

  • getServletContext() method, 40, 48

  • Servlet interface, 3

  • ServletContextAttributeListener interface, 49

ServletContextAttributeEvent class

  • change notification, 4

  • getName() method, 48

  • getValue() method, 48

  • ServletContext lifecycle, 48

ServletContextAttributeListener interface

  • attributeAdded() method, 49

  • attributeRemoved() method, 49

  • attributeReplaced() method, 49

  • ServletContext lifecycle, 49

ServletContextEvent class

  • change notification, 4

  • getServletContext() method, 48

  • ServletContext lifecycle, 48

ServletContextListener interface

  • contextDestroyed() method, 49

  • contextInitialized() method, 49

  • lifecycle interface, 3

  • ServletContext lifecycle, 49

ServletException class

  • exception handling process, 55

  • general exceptions, 4

  • getRootCause() method, 55

  • ServletException() constructors, 55

ServletException() constructors

  • ServletException class, 55

ServletInputStream class, 35

  • I/O streams, 4, 34

  • steps to read java objects, 35

ServletOutputStream class, 35

  • I/O streams, 4, 34

  • steps to wrap java objects, 35

ServletOutputStream object

  • getOutputStream() method, 31

ServletRequest interface, 19-29

  • getCharacterEncoding() method, 25

  • getLocale() method, 24

  • getLocales() method, 25

  • getParameter() method, 19

  • getParameterMap() method, 20

  • getParameterNames() method, 19

  • getParameterValues() method, 19

  • getRequestDispatcher() method, 28

  • getRequestTable() method, 23, 24

  • getScheme() method, 23

  • getServerName() method, 23

  • getServerPort() method, 23

  • internationalization, 24

  • isSecure() method, 24

  • parameter names and values, 19

  • path information, 23

  • request header information, accessing, 20

  • request-response cycle, 14

  • setCharacterEncoding() method, 25

  • using internationalization in request, 24

ServletRequestWrapper class, javax.servlet

  • request-response cycle, 14

  • wrapping objects, 4

ServletResponse interface, 29-34

  • content length, setting, 29

  • internationalization, using in response, 29

  • MIME types, setting, 29

  • output buffering, 31

  • returning data in response, 31

ServletResponseWrapper class, javax.servlet

  • request-response cycle, 14

  • wrapping objects, 4

servlets

  • environment methods, 8

  • getContextTable() method, 43

  • getServletName() method, 40

  • getting servlet information, 7

  • input and output streams, 34

  • lifecycle defined, 6

  • request-response cycle, 14

  • threading issues, 7

  • Tomcat, compiling and running on, 12

setAttribute() method

  • request header information, 22

  • ServletContext attributes, 42

setBufferSize() method

  • output buffering, 31

setCharacterEncoding() method

  • call before getInputStreams() method, 25

  • call before getReader() method, 25

  • internationalization, 25

setContentLength() method

  • setting content length, 29

setContentType() method

  • setting MIME types, 29

setLocale() method

  • using internationalization in response, 29

SingleThreadModel interface

  • request handling, 3

  • threading, 49

storeAttribute() method

  • request header information, 22

SubscribeServlet class

  • personalPortal web application, 67

superclass method call

  • eliminated in init() method, 8

synchronization

  • SingleThreadModel interface, 49

T

threading

  • servlet threading issues, 7

  • SingleThreadModel interface, 49

Tomcat

  • compiling and running servlets, 12

toString() method

  • HTMLTable utility class, 18

toStringBuffer() method

  • HTMLTable utility class, 18

U

UnavailableException class

  • getUnavailableSeconds() method, 56

  • isPermanent() method, 56

  • unavailable filter/servlet, 5

  • UnavailableException() constructors, 55

UnavailableException() constructors

  • UnavailableException class, 55

utility methods

  • log() method, 9

  • ServletContext interface, 47

W

web applications

  • getServletContextName() method, 43

  • personalPortal web application, 56

wrapper classes

  • !see also classes.

  • IO stream wrapper classes, Servlet API, 26

  • request-response cycle, 14

wrapper objects

  • RequestDispatcher object, 44



 < Free Open Study > 



Professional Java Servlets 2.3
Professional Java Servlets 2.3
ISBN: 186100561X
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net