chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · apache...

21
671 Chapter A ACCEPT attribute, file upload controls, 640 Accept header, 147, 152–153 Accept-Charset header, 153 Accept-Encoding header, 147, 153 Accept-Language header, 153 Access, See Microsoft Access AccessCountBean.java, 419 AccessCounts.jsp, 341–342 addCookie method, 196, 204, 237–238 align attribute, jsp:plugin element, 390 ALIGN attribute: IMAGE element, 642 LEGEND element, 649 Allow header, 197 Ant, 52 Apache Log4J, using to debug servlets, 91 Apache Tomcat, 9, 19, 21, 23–28, 238 autogenerated code for JSP pages, viewing, 663 autogenerated servlet source code, 327 basic server setup, testing, 27–28 bookmarking servlet/JSP APIs, 659–660 configuring, 23–28, 660 CATALINA_HOME, setting, 24, 27 DOS memory limits, increasing, 24, 27 invoker servlet, turning on, 24, 26–27 JAVA_HOME variable, setting, 23, 24–25 ROOT context, enabling, 24, 26 server port, specifying, 23, 25 servlet reloading, enabling, 23, 26 custom Web applications, using, 661–662 default Web application, 607–608, 661 deployment directories, 53 development environment, setting up, 660 home page, 28 HTML/JSP directory, 41 JSP directories for, 312–313 “Out of Environment Space” error message, 27 software, downloading, 21, 659 Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp, 360–362 Application-based data sharing, 459–461 MVC code for, 444–445 JSP page, 445 servlet, 444–445 PrimeBean.java, 459–460 PrimeServlet.java, 460–461 ShowPrime.jsp, 461 archive attribute, jsp:plugin element, 390 Arithmetic operators, JSP 2.0 expression language, 487–488 % and mod, 488 *, /, div, 488 + and -, 487 AUTH_TYPE CGI variable, 168 Authorization header, 153 autoFlush attribute, 362–363 Auto-reloading pages, 206 B BakedBeanDisplay-application.jsp, 431–432 BakedBeanDisplay-page.jsp, 424–425 BakedBeanDisplay-request.jsp, 426–427 BakedBeanDisplay-session.jsp, 428–430 BakedBeanDisplay-snippet.jsp, 426 BakedBean.java, 429 BakedBeanTest.java, 430 Bank account balance MVC application, 446–453 BankCustomer.java, 447–448 HighBalance.jsp, 451–452 NegativeBalance.jsp, 449 NormalBalance.jsp, 449–450 ShowBalance.java, 446–447 UnknownCustomer.jsp, 453

Upload: others

Post on 19-Oct-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

671

Chapter

A

ACCEPT attribute, file upload controls, 640Accept header, 147, 152–153Accept-Charset header, 153Accept-Encoding header, 147, 153Accept-Language header, 153Access, See Microsoft AccessAccessCountBean.java, 419AccessCounts.jsp, 341–342addCookie method, 196, 204, 237–238align attribute, jsp:plugin element, 390ALIGN attribute:

IMAGE element, 642LEGEND element, 649

Allow header, 197Ant, 52Apache Log4J, using to debug servlets, 91Apache Tomcat, 9, 19, 21, 23–28, 238

autogenerated code for JSP pages, viewing, 663autogenerated servlet source code, 327basic server setup, testing, 27–28bookmarking servlet/JSP APIs, 659–660configuring, 23–28, 660

CATALINA_HOME, setting, 24, 27DOS memory limits, increasing, 24, 27invoker servlet, turning on, 24, 26–27JAVA_HOME variable, setting, 23, 24–25ROOT context, enabling, 24, 26server port, specifying, 23, 25servlet reloading, enabling, 23, 26

custom Web applications, using, 661–662default Web application, 607–608, 661deployment directories, 53development environment, setting up, 660home page, 28HTML/JSP directory, 41JSP directories for, 312–313“Out of Environment Space” error message, 27

software, downloading, 21, 659Apache Struts, See Volume 2Apache Web server, 8, 21ApplesAndOranges.java, 205ApplesAndOranges.jsp, 360–362Application-based data sharing, 459–461

MVC code for, 444–445JSP page, 445servlet, 444–445

PrimeBean.java, 459–460PrimeServlet.java, 460–461ShowPrime.jsp, 461

archive attribute, jsp:plugin element, 390Arithmetic operators, JSP 2.0 expression language,

487–488% and mod, 488*, /, div, 488+ and -, 487

AUTH_TYPE CGI variable, 168Authorization header, 153autoFlush attribute, 362–363Auto-reloading pages, 206

B

BakedBeanDisplay-application.jsp, 431–432BakedBeanDisplay-page.jsp, 424–425BakedBeanDisplay-request.jsp, 426–427BakedBeanDisplay-session.jsp, 428–430BakedBeanDisplay-snippet.jsp, 426BakedBean.java, 429BakedBeanTest.java, 430Bank account balance MVC application, 446–453

BankCustomer.java, 447–448HighBalance.jsp, 451–452NegativeBalance.jsp, 449NormalBalance.jsp, 449–450ShowBalance.java, 446–447UnknownCustomer.jsp, 453

index.fm Page 671 Monday, July 28, 2003 10:33 AM

Page 2: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index672

BankCustomer.java, 447–448Basic server configuration, checking, 40–42BEA WebLogic, 9, 18Bean classes, installing, 403beanName attribute, jsp:useBean action, 404BeanProperties.java, 477Bean-properties.jsp, 480Beans, in JSP, 398–432BeanUtilities.java, 128–129bgColor form parameter, 110BGColor.jsp, 334–335BidInfo.java, 142–144BidServlet.java, 138–142bodyFont form parameter, 110bodySize form parameter, 110Borland JBuilder, 91Browser sessions vs. server sessions, 271–272BrowserInsult.java, 162–163buffer attribute, 363–364BufferedImage class, 218–219BUTTON element, 628–629

ButtonElement.html, 628NAME attribute, 628ONBLUR attribute, 628ONCLICK attribute, 628ONDBLCLICK attribute, 628ONFOCUS attribute, 628VALUE attribute, 628

C

C++, 8Cache-Control header, HTTP 1.1 response header,

198Callable statements, JDBC:

CallableStatements.java, 537–540creating, 534–541defining the call to the database procedure,

535–536discount.sql, 540–541example, 537–541input parameters, providing values for, 536output parameter types, registering, 536output parameters, accessing, 536preparing a CallableStatement for the

procedure, 536providing values for the input parameters, 536registering the output parameter types, 536

stored procedure, executing, 536Castor, 547CATALINA_HOME, setting, 24, 27CatalogItem.java, 294–295Catalog.java, 297–299CatalogPage.java, 281–284Caucho’s Resin, See ResinCGI, 8Check boxes, HTML, 631–632CHECKED attribute, radio buttons, 634Checkout.html, 291–292checkUserRequest method, 360ClassCastException, 404ClientAccessCount.java, 253–254Client-side image map, 641close method, Connection class, 504CocoBase, 547code attribute, jsp:plugin element, 390codebase attribute, jsp:plugin element, 390Collections.java, 482–483collections.jsp, 483COLS attribute, TEXTAREA element, 624Combo boxes, 634–639CompanyBean.java, 479ComputeSpeed.jsp, 365–367Conditionals.java, 492conditionals.jsp, 493–494Configuration:

Apache Tomcat, 23–28, 660CATALINA_HOME, setting, 24, 27DOS memory limits, increasing, 24, 27invoker servlet, turning on, 24, 26–27JAVA_HOME variable, setting, 23, 24–25ROOT content, enabling, 24, 26server port, specifying, 23, 25servlet reloading, enabling, 23, 26

Database Configuration Assistant (DBCA), 574–581

database configuration, reviewing, 580database connection option, selecting, 578database creation options, selecting, 579database creation process, monitoring, 580database features to install, selecting, 577database identification, providing, 576database template, selecting, 576initialization parameters, specifying, 578passwords, specifiying, 581selecting an operation, 575

index.fm Page 672 Monday, July 28, 2003 10:33 AM

Page 3: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 673

starting, 574storage parameters, specifying, 579

JRun, 28–33, 664administrator username and password, 30–31autostart capability, 31Java installation location, 28, 30serial number, 28, 29server installation location, 28, 30server port, 32–33user restrictions, 28, 29

Microsoft Access, 556–560selecting a data source, 558–559selecting a driver for the new system DSN,

558selecting a system DSN from the ODBC

Data Source Administrator, 557–558selecting OK to accept the new DSN,

559–560Oracle9i, 563–590

database, 568Resin, 34–35, 667–668

JAVA_HOME variable, setting, 34Resin port, specifying, 34

server, 22–63Connection header:

HTTP 1.1 request header, 147, 154HTTP 1.1 response header, 198–199

ConnectionInfoBean.java, 518, 527–529CONTENT_LENGTH CGI variable, 168CONTENT_TYPE CGI variable, 168Content-Encoding header, 199Content-Language header, 199Content-Length header:

HTTP 1.1 request header, 154HTTP 1.1 response header, 199

Content-Type header, 200–201Cookie header, 147, 154Cookies, 264

advertising, focusing, 231attributes:

getComment method, 242getDomain method, 242getMaxAge method, 242getName method, 243getPath method, 243getSecure method, 243getValue method, 244getVersion method, 244

setComment method, 242setDomain method, 242setMaxAge method, 242setPath method, 243setSecure method, 243setValue method, 244setVersion method, 244using, 241–244

basic utilities, 248–250CookieUtilities.java, 248–249finding cookies with specified names,

248–249long-lived cookies, creating, 250LongLivedCookie.java, 250

benefits of, 229–231cookie utilities, putting into practice, 250–252customizing sites, 231deleting, 234–235handling, 228–260persistent cookies:

CookieTest.java, 245–247differentiating session cookies from, 244–247

problems with, 231–234reading cookies from the client, 238–239

calling request.getCookies, 238looping down the cookie array, 238–239

RegistrationForm.java, 255–256, 259–260RegistrationServlet.java, 257–258RepeatVisitor.java, 240–241RepeatVisitor2.java, 250–252sending to the client, 236–238

creating a cookie object, 236placing the cookie in the response headers,

237–238setting the maximum age, 237

user access counts:ClientAccessCount.java, 253–254tracking, 252–254

user, identifying during an E-commerce session, 230

user preferences, using cookies to remember, 255–260

usernames/passwords, remembering, 230–231using to detect first-time visitors, 239–241

RepeatVisitor.java, 240–241RepeatVisitor2.java, 250–252

values, modifying, 252–254CookieTest.java, 245–247

index.fm Page 673 Monday, July 28, 2003 10:33 AM

Page 4: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index674

CookieUtilities.java, 248–249Core Java Data Objects (Tyagi et al.), 547coreservlets package, 72courses.coreservlets.com, xxxiiicreate_csajsp.sql, 588create_music_table.sql, using to create, 602–604CreateMusicTable.java, using to create, 599–602createStatement method, 505Custom URLs:

assigning to servlets, 60–63base format, defining, 61deployment descriptor:

locating, 61reading, 62

example, 62–63giving URLs, 61servlets, naming, 61WEB-INF/web.xml, 62–63

Custom tags, JSP, See Volume 2Custom Web applications, 55-63CustomizeImage.java, 164–167

D

Databases, 498–604testing through a JDBC connection, 590–599

TestDatabase.java, 592–599Database Configuration Assistant (DBCA),

574–581database configuration, reviewing, 580database connection option, selecting, 578database creation options, selecting, 579database creation process, monitoring, 580database features to install, selecting, 577database identification, providing, 576database template, selecting, 576initialization parameters, specifying, 578passwords, specifying, 581selecting an operation, 575starting, 574storage parameters, specifying, 579

Database transactions:TransactionBean.java, 544–546Transactions.java, 543–544using, 541–546

Data-sharing approaches:application-based sharing, 459–461

PrimeBean.java, 459–460

PrimeServlet.java, 460–461ShowPrime.jsp, 461

comparison of, 453–461including pages, 463JSP pages, forwarding requests from, 462request-based sharing, 454–455

NumberBean.java, 454RandomNumberServlet.java, 454–455RandomNum.jsp, 455

session-based sharing, 456–459NameBean.java, 456RegistrationServlet.java, 457–459ShowName.jsp, 458

DayWish.jsp, 336DBCA, See Database Configuration Assistant

(DBCA)Debugging servlets, 90–92Declarations, 321

AccessCounts.jsp, 341–342comparing to scriptlets and expressions, 344–350example, 340–342JSP/servlet correspondence, 339–340using, 338–340XML syntax for, 340

Default values, using for incomplete forms, 108–119

Deployment directories:Apache Tomcat, 53JRun, 53–54Resin, 54–55

Deployment directories, for default Web applica-tions, 52–55

destroy method, 77, 85Development environment:

Apache Tomcat, setting up, 660bookmarking/installing the servlet/JSP API

documentation, 39CLASSPATH, setting, 36–38development directory, creating, 36integrated development environments (IDEs), 91JRun, setting up, 664Resin, setting up, 668setting up, 17, 35–39shortcuts to start/stop the server, 38

Dilbert, 109, 157, 499Directives, 352–370

ApplesAndOranges.jsp, 360–362autoFlush attribute, page directive, 362–363

index.fm Page 674 Monday, July 28, 2003 10:33 AM

Page 5: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 675

buffer attribute, page directive, 363–364ComputeSpeed.jsp, 365–367contentType attribute, page directive, 357–359errorPage attribute, page directive, 364–367Excel spreadsheets:

conditionally generating, 359–362generating, 358–359

extends attribute, page directive, 369import attribute, page directive, 354–357info attribute, page directive, 364isELIgnored attribute, page directive, 363isErrorPage attribute, page directive, 364–367isThreadSafe attribute, page directive, 367–369language attribute, page directive, 369pageEncoding attribute, page directive, 357–359session attribute, page directive, 362SpeedErrors.jsp, 366–367XML syntax for, 370

DOCTYPE declaration, HTML, 74–75DOCUMENT_ROOT CGI variable, 168doDelete method, 77doGet method, 6, 67, 77–79, 84, 86, 97, 106, 168,

207, 342doHead method, 78doPost method, 67, 77–79, 86, 97, 106, 168, 207doPut method, 77–78doTrace method, 78doXxx methods, 78–79DrawingPanel.java, 394–395DriverInfoBean.java, 518, 526–527drivers.xml, 525–526DriverUtilities.java, 518–522DriverUtilities2.java, 518, 522–525

E

EchoServer, 650–657EchoServer.java, 651–654NetworkServer.java, 654–656SocketUtil.java, 656–657

email form parameter, 110EmployeeBean.java, 478empty operator, JSP 2.0 expression language, 489Empty string, from request.getParameter, 109encodeRedirectURL method, 273encodeURL method, 273Enterprise JavaBeans (EJB), 9, 18errorPage attribute, page directive, 364–367executeBatch method, 505

executeQuery method, 505executeUpdate method, 505Expires header, 202Expression language, JSP 2.0, 464–495Expressions.jsp, 328–329extends attribute, page directive, 369

F

fgColor request parameter, 110FIELDSET element, HTML, 647–649

Fieldset.html, 648File upload controls, 639–641

ACCEPT attribute, 640example of, 640MAXLENGTH attribute, 640NAME attribute, 640ONBLUR attribute, 640ONCHANGE attribute, 640ONFOCUS attribute, 640ONSELECT attribute, 640SIZE attribute, 640VALUE attribute, 640

Filters, JSP, See Volume 2findColumn method, 507findPrimeList method, 207First-time visitors, using cookies to detect, 239–241Form beans, 127–134

BeanUtilities.java, 128–129InsuranceForm.html, 132InsuranceInfo.java, 131–132Jakarta Commons packages, obtaining/install-

ing, 133–134putting BeanUtilities to work, 130–133SubmitInsuranceInfo. java, 130–131

Form data, 94–144default values:

SubmitResume.html, 111–112SubmitResume.java, 113–117using, 108–119

filtering strings for HTML-specific characters, 120–126

BadCodeServlet.java, 124–125code for filtering, 121CodeForm1.html, 123CodeForm2.html, 126GoodCodeServlet.java, 126servlet displaying code snippets, 123–126ServletUtilities.java, 121–122

index.fm Page 675 Monday, July 28, 2003 10:33 AM

Page 6: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index676

Form data (cont.):form beans, 127–134

BeanUtilities.java, 128–129InsuranceForm.html, 132.InsuranceInfo.java, 131–132Jakarta Commons packages, obtaining/install-

ing, 133–134putting BeanUtilities to work, 130–133SubmitInsuranceInfo. java, 130–131

reading from servlets, 97–100getInputStream method, 99getParameter method, 97getParameterMap method, 98–99getParameterNames method, 98–99getParameterValues method, 98getReader method, 99setCharacterEncoding method, 99–100ShowParameters.java, 104–108ShowParametersPostForm.html, 106–107ThreeParams. java, 100–104ThreeParamsForm.html, 102

redisplaying the input form, 134–144redisplay options, 135–136servlet that processes auction bids, 136–144

role of, 95–97FORM element, using to create an HTML form, 96forward method, RequestDispatcher, 386, 425,

440–441, 463FrontierSuite, 547

G

GET data, 74getAddress method, 476getAttribute method, 207, 344, 417, 418getAttributeNames method, 2676getAuthType method, 148getBufferSize method, 70getColumnCount method, 508getColumnName method, 508getColumnType method, 508getComment method, 242getContentLength method, 148getContentType method, 148getCookie method, 248getCookies method, 148, 238getCookieValue method, 248getDateHeader method, 149

getDomain method, 242getGoesWith method, 422getGraphics method, 218getHeader method, 148getHeaderNames method, 149getHeaders method, 149getInitParameter method, 85getInputStream method, 99getIntHeader method, 149getLastModified method, 78–80, 84, 155, 181, 202getLevel method, 422getMaxAge method, 242getMaxRows method, 506getMessage method, 406getMetaData method, 508getMethod method, 149getName method, 243getOutputStream method, 218, 219getParameter method, 92, 97, 98, 127getParameterMap method, 98–99getParameterNames method, 98–99, 104getParameterValues method, 98, 104getPath method, 243getProtocol method, 149getQueryString method, 149getReader method, 99getRealPath method, 167getRemoteAddress method, 167getRemoteHost method, 167getRemoteUser method, 148getRequestDispatcher method, 440getRequestURI method, 149getRow method, 508getSecure method, 243getServletConfig method, 85getServletContext method, 167, 207getServletInfo method, 364getSession method, 266–267getValue method, 244, 485getVersion method, 244getWriter method, 219getXxx method, 507getZipCode method, 476GIF images, 4Gzip, 156–157GzipUtilities.java, 159–160

index.fm Page 676 Monday, July 28, 2003 10:33 AM

Page 7: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 677

H

hasMoreElements method, Enumeration, 98, 150headingFont, 110headingSize, 110height attribute, jsp:plugin element, 390Hello.html, 41, 59Hello.jsp, 42, 59HelloServlet2 class, 60

invoked with custom URL, 63HelloServlet3 class, 60

invoked with custom URL, 63HelloServlet class, 7, 43, 44, 59, 71–72

invoked with custom URL, 63HelloWorld class, 68–69Hidden fields, HTML forms, 646–647HighBalance.jsp, 451–452Host header, 147–148, 154hspace attribute, jsp:plugin element, 390HTML forms:

check boxes, 631–632combo boxes, 634–639creating/processing, 606–657and data transmission, 608–612

GetForm.html, 609–610PostForm.html, 611–612

default Web application:Apache Tomcat, 607–608JRun, 608Resin, 608

EchoServer, 650–657EchoServer.java, 651–654NetworkServer.java, 654–656SocketUtil.java, 656–657

FIELDSET element, 647–649Fieldset.html, 648

file upload controls, 639–641form data, 5FORM element, 613–620

ACCEPT attribute, 620ACCEPT-CHARSET attribute, 620ACTION attribute, 613–614ENCTYPE attribute, 615–617METHOD attribute, 614–615MultipartForm.html, 618–619ONRESET attribute, 619ONSUBMIT attribute, 619TARGET attribute, 619

hidden fields, 646–647

LEGEND element, 649list boxes, 634–639push buttons, 625–630

JavaScript buttons, 630reset buttons, 629–630submit buttons, 626–629

radio buttons, 632–634server-side image maps, 641–646

IMAGE element, 642–644ISMAP, 644–646

tab order control, 649–650Tabindex.html, 649–650

text controls, 620–625password fields, 623text area, 624–625textfields, 620–622

HTML source, debugging servlets using, 92HTTP 1.1 request headers:

Accept header, 147, 152–153Accept-Charset header, 153Accept-Encoding header, 147, 153Accept-Language header, 153Authorization header, 153Connection header, 147, 154Content-Length header, 154Cookie header, 154Host header, 147–148, 154If-Modified-Since header, 155If-Unmodified-Since header, 155Referer header, 147–148, 155, 163–164understanding, 152–156User-Agent header, 147–148, 156, 161

HTTP 1.1 response headers:Allow header, 197Cache-Control header, 198Connection header, 198–199Content-Encoding header, 199Content-Language header, 199Content-Length header, 199Content-Type header, 200–201Expires header, 202Last-Modified header, 202Location header, 202Pragma header, 203Refresh header, 203Retry-After header, 203Set-Cookie header, 204understanding, 197–204WWW-Authenticate header, 195, 204

index.fm Page 677 Monday, July 28, 2003 10:33 AM

Page 8: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index678

HTTP 1.1 status codes, 178–184100 (Continue), 179200 (OK), 179202 (Accepted), 179204 (No Content), 179205 (Reset Content), 179301 (Moved Permanently), 179302 (Found), 179–181302 (See Other), 181304 (Not Modified), 181307 (Temporary Redirect), 181400 (Bad Request), 181401 (Unauthorized), 181–182403 (Forbidden), 182404 (Not Found), 182–183405 (Method Not Allowed), 183415 (Unsupported Media Type), 183417 (Expectation Failed), 183500 (Internal Server Error), 183501 (Not Implemented), 183503 (HTTP Version Not Supported), 184503 (Service Unavailable), 183categories of, 178redirects, 180–181

HTTP Content-Type response header, 70HTTP request headers, 5, 146–172

browser types, differentiating among, 161–163compressed Web pages:

GzipUtilites.java, 159–160LongServlet.java, 158–159sending, 156–160

customizing the page depending on how the user reached it, 163–167

CustomizeImage.java, 164–167JRun-Referer.html, 165

front end to search engines, 186–192SearchEngineForm.java, 192SearchEngines.java, 186–187, 190–191SearchSpec.java, 188SearchUtilities.java, 188–189

getHeader method, 148HTTP 1.1 request headers, understanding,

152–156making a table of all request headers, 150–152reading, 148–149servlet that redirect users to browser-specific

pages, 184–185WrongDestination. java, 184–185

ShowRequestHeaders.java, 150–151standard CGI variables:

assessing, 167–173servlet equivalent of CGI variables, 168–170servlet that shows the CGI variables, 170–173

HTTP response headers, 194–227Excel spreadsheets:

ApplesAndOranges.java, 205building, 204–205

HTTP 1.1 response headers, understanding, 197–204

persistent servlet state and auto-reloading pages, 206

prime numbers:finding for use with public key cryptography,

206–217PrimeList.java, 212, 213–214PrimeNumberServlet.java, 208–209PrimeNumbers.html, 210Primes.java, 212, 215–216ServletUtilities.java, 217

setting from servlets, 196–197addCookie method, 196sendRedirect method, 197setContentLength method, 196setContentType method, 196setDateHeader method, 196setHeader method, 196setIntHeader method, 196

using servlets to generate JPEG images, 217–227

BufferedImage class, 218–219ImageTest.java, 227MessageImage.java, 221–223non-HTML content, building, 218–219ShadowedText.html, 224ShadowedText.java, 220–221

HTTP status codes, 174–192arbitrary status codes, setting, 176–177HTTP 1.1 status codes, 178–184send Error method, 177sendRedirect method, 177setStatus method, 176–177specifying, 176–177

HTTP_XXX_YYY CGI variable, 168HttpServlet class, 6, 91HttpServletRequest, 67, 148HttpServletResponse, 70

index.fm Page 678 Monday, July 28, 2003 10:33 AM

Page 9: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 679

I

IBM WebSphere, 18, 91iepluginurl attribute, jsp:plugin element, 391If-Modified-Since header, 155If-Unmodified-Since header, 155IMAGE element, 642–644

ALIGN attribute, 642ImageMap.html, 643NAME attribute, 642SRC attribute, 642

ImageTest.java, 227include method, 374, 381, 425, 463info attribute, 364init method, 79–85, 90, 92

general initializations, 79–84initializations controlled by initialization parame-

ters, 84–85JSP equivalent, See jspInit

initCSAJSP.ora, 583–585INPUT element, HTML forms, 620–622

MAXLENGTH attribute, 622NAME attribute, 621ONBLUR attribute, 622ONCHANGE attribute, 622ONDBLDOWN attribute, 622ONFOCUS attribute, 622ONKEYPRESS attribute, 622ONKEYUP attribute, 622ONSELECT attribute, 622SIZE attribute, 622VALUE attribute, 621

input elements, using to collect user data, 96instantiate method, java.beans.Bean, 404InsuranceForm.html, 132.InsuranceInfo.java, 131–132Integrated debugger in IDE, using to debug

servlets, 91Integrated development environments (IDEs), 91iPlanet/Sun ONE Server, 21isClosed method, 504isELIgnored attribute, page directive, 363isGzipSupported method, 157ISMAP, 644–646

IsMap.html, 645isNullable method, 508isReadOnly method, 508isSearchable method, 508

isThreadSafe attribute, page directive, 367–369ItemOrder.java, 295–297

J

Jakarta Commons packages, obtaining/installing, 133–134

Java 2 Platform:Enterprise Edition (J2EE), 6Standard Edition (J2SE), 6

Java code, limiting in JSP pages, 321–323Java objects, automatically populating from request

parameters, 127–134JavaServer Faces (JSF), See Volume 2Java Software Development Kit (SDK), download-

ing/installing, 17, 18–19JavaBeans, 398–432

AccessCountBean.java, 419basic tasks, 402–406bean classes, installing, 403building, 402–403creating conditionally, 418–421defined, 400–402extracting data from, 443individual properties, associating with individual

parameters, 414–415jsp:getProperty action, 405jsp:setProperty action, 405–406jsp:useBean action, 402–403

beanName attribute, 404scope attribute, 404type attribute, 404

reasons for using, 400request parameters, associating all properties

with, 415–416SaleEntry1-Form.jsp, 413SaleEntry1.jsp, 411–413SaleEntry.java, 410–411setting bean properties, advanced techniques,

409–416SharedCounts1.jsp, 420–421sharing, 417–421

example, 421–432StringBean class, 406–408

StringBean.java, 407StringBean.jsp, 408

JavaScript buttons, 630JAXB, See Volume 2

index.fm Page 679 Monday, July 28, 2003 10:33 AM

Page 10: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index680

JBoss, 18JBuilder, 91JDBC, 498–553

basic examples, 509–516NorthwindForm.html, 514–515NorthwindServlet.java, 512–514NorthwindTest result, 511NorthwindTest.java, 510–511

callable statements:CallableStatements.java, 537–540creating, 534–541defining the call to the database procedure,

535–536discount.sql, 540–541example, 537–541output parameters, accessing, 536preparing a CallableStatement for the

procedure, 536providing values for the input parameters,

536registering the output parameter types, 536stored procedure, executing, 536

closing the connection, 501, 509connection, establishing, 501, 504–505connection URL, defining, 501, 504ConnectionInfoBean.java, 518, 527–529database transactions:

TransactionBean.java, 544–546Transactions.java, 543–544using, 541–546

defined, 498–499DriverInfoBean.java, 518, 526–527drivers.xml, 525–526DriverUtilities2.java, 518, 522–525DriverUtilities.java, 518–522JDBC driver, loading, 500–503object-to-relational mapping (ORM) frame-

works, 546–553prepared statements, using, 530–534

PreparedStatements.java, 531–534processing the results, 501, 506–508query/update, executing, 501, 505–506Statement object, creating, 501, 505using, 500–509utilities, simplying database access with,

517–529JDeveloper (Oracle), 91Jetty, 22

jreversion attribute, jsp:plugin element, 391JRun, 9, 19, 21

autogenerated code for JSP pages, viewing, 665–666

autogenerated servlet source code, 327basic server set up, testing, 33bookmarking servlet/JSP APIs, 663configuring, 28–33, 664

administrator username and password, 30–31autostart capability, 31Java installation location, 28, 30serial number, 28, 29server installation location, 28, 30server port, 32–33user restrictions, 28, 29

custom Web applications, using, 665–666default Web application, 608, 664–665deployment directories, 53–54development environment, setting up, 664HTML/JSP directory, 41JSP directories for, 313software, downloading, 663

JRun-Referer.html, 165JSF (JavaServer Faces), See Volume 2JSP:

Active Server Pages (ASP) compared to, 306–307

applets, including for the Java plug-in, 386–396basic syntax, 314–317

custom tag (custom action), 316excaped template text, 317HTML comments, 314HTML text, 314JSP action, 316JSP comment, 314–315JSP declaration, 315JSP directive, 315–316JSP expression, 315JSP expression language element, 316JSP scriptlet, 315template text, 314

benefits of, 305–306comparing servlets to, 330–331competing technologies, advantages over,

306–309directories for Apache Tomcat, 312–313directories for JRun, 313directories for Resin, 313

index.fm Page 680 Monday, July 28, 2003 10:33 AM

Page 11: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 681

DrawingPanel.java, 394–395forwarding requests from, 462forwarding requests to, 440–442

example, 441forwarding to static resources, 441–442redirecting, 442

include directive, 373, 380–386JavaScript compared to, 308JSP 2.0 expression language, 309JSP pages, installation of, 312–313JSP Standard Tag Library, 309jsp:fallback element, 392jsp:forward, 386jsp:include action, 373, 374–380jspInit method, 310–311, 338, 341, 344jsp:param element, 391jsp:params element, 391jsp:plugin element, 373–374, 389–391

align attribute, 390archive attribute, 390code attribute, 390codebase attribute, 390example, 392–396height attribute, 390hspace attribute, 390iepluginurl attribute, 391jreversion attribute, 391name attribute, 390nspluginurl attribute, 391title attribute, 390type attribute, 389vspace attribute, 390width attribute, 390

misconceptions about, 309–312need for, 304–305.NET Hatch compared to, 306–307OrderConfirmation.jsp, 303–304overview of, 302–317PHP compared to, 307PluginApplet.java, 393PluginApplet.jsp, 392–393, 396pure servlets compared to, 307–308role of, 11–12server, and set up/configuration, 16–63as server-side technology, 309–310strategies for invoking dynamic code from, 399,

436, 466

TextPanel.java, 393–394translation time, confusing with request time, 310using other tools, 311–312Velocity compared to, 308–309WebMacro compared to, 308–309WindowUtilities.java, 395–398

JSP 2.0 expression language, 309, 464–495accessing bean properties, 475–480

array notation, equivalence of, 476BeanProperties.java, 477bean-properties.jsp, 480CompanyBean.java, 479dot notation, equivalence of, 476EmployeeBean.java, 478example, 477–480NameBean.java, 478–479

accessing collections, 481–483Collections.java, 482–483collections.jsp, 483

accessing scoped variables, 472–475attribute names, choosing, 473example, 473–475ScopedVars.java, 473–474scoped-vars.jsp, 474

deactivating in individual JSP pages, 470deactivating in individual statements, 470–471deactivating in multiple JSP pages, 469–470deactivating in an entire Web application, 469EL usage, motivating, 465–467evaluating conditionally, 491–494

Conditionals.java, 492conditionals.jsp, 493–494example, 492–494SalesBean.java, 493

expression language evaluation, preventing, 468–471

invoking, 467–468escaping special characters, 468

operators, 487–491arithmetic operators, 487–488empty operator, 489example, 489–491logical operators, 489operators.jsp, 489–490relational operators, 488–489

previewing other expression language capabili-ties, 495

index.fm Page 681 Monday, July 28, 2003 10:33 AM

Page 12: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index682

JSP 2.0 expression language (cont.):referencing implicit objects, 483–486

applicationScope, 485cookie, 485example, 485–486header, 484headerValues, 484implicit-objects.jsp, 486initParam, 485pageContent, 484pageScope, 485param, 484paramValues, 484requestScope, 485sessionScope, 485

standard scripting elements, preventing use of, 471

JSP documents, using JavaBeans components in, 398–432

JSP expressions, 321, 325–330application, 325example of, 328–329Expressions.jsp, 328–329JSP/servlet correspondence, 326–327out, 325predefined variables, 325request, 325response, 325session, 325XML syntax for, 327

JSP page directive, 352–370ApplesAndOranges.jsp, 360–362autoFlush attribute, 362–363buffer attribute, 363–364ComputeSpeed.jsp, 365–367contentType attribute, 357–359errorPage attribute, 364–367Excel spreadsheets:

conditionally generating, 359–362generating, 358–359

extends attribute, 369import attribute, 354–357info attribute, 364isELIgnored attribute, 363isErrorPage attribute, 364–367isThreadSafe attribute, 367–369language attribute, 369pageEncoding attribute, 357–359

session attribute, 362SpeedErrors.jsp, 366–367XML syntax for, 370

JSP scripting elements, 318–350comparing servlets to JSP pages, 330–331

ThreeParams.java, 330–331declarations, 321

AccessCounts.jsp, 341–342comparing to scriptlets and expressions,

344–350example, 340–342JSP/servlet correspondence, 339–340using, 338–340XML syntax for, 340

expressions, 321, 325–330comparing to scriptlets and declarations,

344–350example of, 328–329JSP/servlet correspondence, 326–327pre-defined variables, 325XML syntax for, 327

Java code:invoking from JSP, 320–321limiting the amount of, 321–323

packages, importance of using, 323–324predefined variables:

application, 344config, 344out, 343page, 344pageContext, 344request, 343response, 343session, 343using, 342–344

RandomList1.jsp, 347RandomList2.jsp, 348RandomNums.jsp, 346RanUtilities.java, 345scriptlets, 321, 332–334

BGColor.jsp, 334–335comparing to expressions and declarations,

344–350example, 334–335JSP/servlet correspondence, 333using to make parts of JSP page conditional,

336–337writing, 332–334

index.fm Page 682 Monday, July 28, 2003 10:33 AM

Page 13: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 683

XML syntax for scriptlets, 334SemiRandomNumber.jsp, 349–350template text, 319–328types of, 321

JSP Standard Tag Library (JSTL), 516jsp:fallback element, 392jsp:include action, 463jsp:param element, 391jsp:params element, 391jsp:plugin element, 373–374, 389–391

align attribute, 390archive attribute, 390code attribute, 390codebase attribute, 390height attribute, 390hspace attribute, 390ispluginur1 attribute, 391jreversion attribute, 391name attribute, 390nspluginurl attribute, 391title attribute, 390type attribute, 389vspace attribute, 390width attribute, 390

_jspService method, 326, 332–333, 336, 338–339, 342–343, 349, 404, 417

jsp:useBean action, 402–403beanName attribute, 404scope attribute, 404

application value, 418page value, 417, 423–425request value, 417–418session value, 418

type attribute, 404JSTL, See JSP Standard Tag Library

K

KidsBooksPage.java, 284, 285Kodo, 547

L

LABEL attribute, OPTGROUP element, 638language attribute, page directive, 369languages request parameter, 110Last-Modified header, 202Life cycle of servlets, 77–86

destroy method, 85doGet method, 78–79doPost method, 78–79doXxx methods, 78–79init method, 79–83service method, 77–78

List boxes, 634–639Listeners, servlets/JSP, See Volume 2Location header, 202Log4J, Apache, 91Log file, using to debug servlets, 91Logical operators, 489LongLivedCookie.java, 250LongServlet.java, 158–159LotteryNumbers.java, 80–84

M

Macromedia JRun, See JRunMalformed data, planning ahead for, 91–92MAXLENGTH attribute:

file upload controls, 640INPUT element, 622password fields, 623

MessageImage.java, 221–223Microsoft Access:

configuring for use with JDBC, 556–560selecting a data source, 558–559selecting a driver for the new system DSN,

558selecting a system DSN from the ODBC

Data Source Administrator, 557–558selecting OK to accept the new DSN,

559–560Microsoft IIS, 9, 21Middleware, role of, 65MIME types, 200–201Missing data, planning ahead for, 91–92Model View Controller (MVC), 12, 434–463

architecture vs. approach, 437bank account balance application, 446–453

BankCustomer.java, 447–448HighBalance.jsp, 451–452NegativeBalance.jsp, 449NormalBalance.jsp, 449–450ShowBalance.java, 446–447UnknownCustomer.jsp, 453

index.fm Page 683 Tuesday, July 29, 2003 11:22 AM

Page 14: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index684

Model View Controller (MVC) (cont.):data-sharing approaches:

application-based sharing, 459–461comparison of, 453–461request-based sharing, 454–455session-based sharing, 456–459

frameworks, 436–437implementing with RequestDispatcher, 437–443

defining beans to represent the data, 438extracting data from beans, 443forwarding requests to JSP pages, 440–442populating beans, 439storing the results, 439–440writing servlets to handle requests, 438

MVC code summarization, 443–445application-based data sharing, 444–445request-based data sharing, 443–444session-based data sharing, 444

need for, understanding, 435–436relative URLs, interpreting in the destination

page, 445MULTIPLE attribute, SELECT element, 635music table:

create_music_table.sql, using to create, 602–604CreateMusicTable.java, using to create, 599–602setting up, 599–604

MVC, See Model View ControllerMySQL:

database, creating, 561–562downloading, 561installing/configuring, 560–563JDBC driver, installing, 562–563user, creating, 562

N

name attribute, jsp:plugin element, 390NAME attribute:

BUTTON element, 628check boxes, 632file upload controls, 640hidden fields, 646–647IMAGE element, 642INPUT element, 621JavaScript buttons, 630password fields, 623radio buttons, 633reset buttons, 629

SELECT element, 635TEXTAREA element, 624

name request parameter, 110NameBean.java, 456, 478–479NegativeBalance.jsp, 449NewAtlanta ServletExec, 22nextElement method, 98, 150next/previous methods, ResultSet, 507Nonempty string, of the wrong format, 109NormalBalance.jsp, 449–450nspluginurl attribute, jsp:plugin element, 391NullPointerException, 109NumberBean.java, 454numDigits parameter, 207numPrimes parameter, 207

O

ObJectRelationalBridge, 547Object-to-relational mapping (ORM) frameworks,

546–553jdo.properties, 552–553Music.java, 550–551Music.jdo, 549PopulateMusicTable.java, 551–552

ONBLUR attribute:BUTTON element, 628check boxes, 632file upload controls, 640INPUT element, 622JavaScript buttons, 630password fields, 623radio buttons, 634reset buttons, 629–630SELECT element, 635TEXTAREA element, 624–625

ONCHANGE attribute:file upload controls, 640INPUT element, 622password fields, 623SELECT element, 635TEXTAREA element, 624–625

ONCLICK attribute:BUTTON element, 628check boxes, 632JavaScript buttons, 630radio buttons, 634reset buttons, 629–630

index.fm Page 684 Monday, July 28, 2003 10:33 AM

Page 15: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 685

SELECT element, 635ONDBLCLICK attribute:

BUTTON element, 628check boxes, 632JavaScript buttons, 630reset buttons, 629–630

ONDBLDOWN attribute, INPUT element, 622ONFOCUS attribute:

BUTTON element, 628check boxes, 632file upload controls, 640INPUT element, 622JavaScript buttons, 630password fields, 623radio buttons, 634reset buttons, 629–630SELECT element, 635TEXTAREA element, 624–625

ONKEYDOWN attribute:password fields, 623TEXTAREA element, 624–625

ONKEYPRESS attribute:INPUT element, 622password fields, 623TEXTAREA element, 624–625

ONKEYUP attribute:INPUT element, 622password fields, 623TEXTAREA element, 624–625

Online store with shopping cart/session tracking, 281–299

catalog item implementation, 292–299CatalogItem.java, 294–295Catalog.java, 297–299CatalogPage.java, 281–284Checkout.html, 291–292creating the front end, 281–286ItemOrder.java, 295–297KidsBooksPage.java, 284, 285order handling, 286–292OrderPage.java, 287–291shopping cart implementation, 292–299ShoppingCart.java, 292–294TechBooksPage.java, 284, 286

ONSELECT attribute:file upload controls, 640INPUT element, 622password fields, 623

TEXTAREA element, 624–625Operators:

JSP 2.0 expression language, 487–491arithmetic operators, 487–488example, 489–491logical operators, 489operators.jsp, 489–490relational operators, 488–489

operators.jsp, 489–490OPTGROUP element, 638–639

LABEL attribute, 638OPTION element:

SELECTED attribute, 636VALUE attribute, 636

Oracle JDeveloper, 91Oracle9i:

configuration tools, installing, 572configuring, 563–590data dictionary views, running scripts to build,

589database:

creating, 574, 587–588creating an Oracle Service for, 586creating manually, 581–589creating with Database Configuration Assis-

tant (DBCA), 574–581database directories, setting up, 581, 582initialization parameter file, creating, 581,

583–585password file, creating, 581, 585

database configuration, selecting, 568database location, specifying, 570database system identification (SID), providing,

569default character set, specifying, 570downloading, 564–565Enterprise Edition, 563file locations, specifying, 566installation type, selecting, 567installing, 563, 565–566, 571

completing the installation, 573JDBC driver, installing, 589–590list of products, reviewing, 571Oracle instance, starting, 587Oracle MTS Recovery Service, specifying the

port for, 568–569ORACLE_SID value, declaring, 586passwords, specifying, 572–573

index.fm Page 685 Monday, July 28, 2003 10:33 AM

Page 16: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index686

Oracle9i (cont.):Personal Edition, 564selecting a product to install, 567Standard Edition, 563–564starting the installer, 565SYSDBA, connecting to the Oracle Service as,

586–587user, creating, 589user tablespace, creating, 588

Oracle9i AS, 9OrderForm.html, 279–280OrderPage.java, 287–291

P

Packaging servlets, 72–74Password fields, HTML forms, 623PATH_INFO CGI variable, 169PATH_TRANSLATED CGI variable, 169Persistent cookies:

CookieTest.java, 245–247differentiating session cookies from, 244–247

Persistent servlet state and auto-reloading pages, 206

PluginApplet.java, 393PluginApplet.jsp, 392–393, 396POST data, 74Pragma header, HTTP 1.1 response header, 203Predefined variables:

application, 344config, 344out, 343page, 344pageContext, 344request, 343response, 343session, 343using, 342–344

prepareCall method, 504Prepared statements, using, 530–534PreparedStatements.java, 531–534prepareStatement method, 504Prime numbers:

finding for use with public key cryptography, 206–217

PrimeList.java, 212, 213–214PrimeNumberServlet.java, 208–209PrimeNumbers.html, 210

Primes.java, 212, 215–216ServletUtilities.java, 217

PrimeBean.java, 459–460PrimeList.java, 212, 213–214PrimeNumberServlet.java, 208–209PrimeNumbers.html, 210PrimeServlet.java, 460–461Primes.java, 212, 215–216Print statements, using to debug servlets, 90PrintWriter, 70Properties, 127Push buttons, 625–630

JavaScript buttons, 630reset buttons, 629–630submit buttons, 626–629

Q

QUERY_STRING CGI variable, 169

R

Radio buttons, 632–634randomInt method, 344–345RandomList1.jsp, 347RandomList2.jsp, 348RandomNumberServlet.java, 454–455RandomNum.jsp, 455RandomNums.jsp, 346RanUtilities.java, 345Redisplaying the input form, 134–144

redisplay options, 135–136servlet that processes auction bids, 136–144

BidInfo.java, 142–144BidServlet.java, 138–142

Referer header, 147–148, 155, 163–164RegistrationForm.java, 255–256, 259–260RegistrationServlet.java, 257–258, 457–459Relational operators, JSP 2.0, 488–489

< and lt, > and gt, <= and le, and ge, 489= = and eq, 488!= and ne, 488

relative/absolute methods, ResultSet, 507REMOTE_ADDR CGI variable, 169REMOTE_HOST CGI variable, 169REMOTE_USER CGI variable, 169removeAttribute method, 268RepeatVisitor2.java, 250–252

index.fm Page 686 Monday, July 28, 2003 10:33 AM

Page 17: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 687

RepeatVisitor.java, 240–241replaceIfMissing method, 110replaceIfMissingOrDefault method, 110Request data, looking at separately, 92REQUEST_METHOD CGI variable, 170Request-based data sharing, 425–427, 454–455

MVC code, 443–444NumberBean.java, 454RandomNumberServlet.java, 454–455RandomNum.jsp, 455

RequestDispatcher, 437–443implementing MVC with, 437–443

defining beans to represent the data, 438extracting data from beans, 443forwarding requests to JSP pages, 440–442populating beans, 439storing the results, 439–440writing servlets to handle requests, 438

Reset buttons, 629–630NAME attribute, 629ONBLUR attribute, 629–630ONCLICK attribute, 629–630ONDBLCLICK attribute, 629–630ONFOCUS attribute, 629–630VALUE attribute, 629

Resin, 9, 19, 22autogenerated code for JSP pages, viewing, 670autogenerated servlet source code, 327basic server set up, testing, 34bookmarking servlet/JSP APIs, 667configuring, 34–35

JAVA_HOME variable, setting, 34Resin port, specifying, 34

configuring the server, 667–668custom Web applications, using, 669–670default Web application, 608, 668–669deployment directories, 54–55development environment, setting up, 668home page, 35HTML/JSP directory, 41JSP directories for, 313software, downloading, 667

Response data, looking at separately, 92ResultSet methods, 507–508Retry-After header, 203rolback/commit method, ResultSet, 504ROWS attribute, TEXTAREA element, 624

S

SaleEntry1-Form.jsp, 413SaleEntry1.jsp, 411–413SaleEntry2.jsp, 415SaleEntry.java, 410–411SalesBean.java, 493scope attribute, jsp:useBean action, 404ScopedVars.java, 473–474scoped-vars.jsp, 474SCRIPT_NAME CGI variable, 170Scripting, JSP: classic, 318-350 JSP 2.0, 464–495Scriptlets, 321, 332–334

BGColor.jsp, 334–335comparing to expressions and declarations,

344–350DayWish.jsp, 336example, 334–335JSP/servlet correspondence, 333using to make parts of JSP page conditional,

336–337writing, 332–334XML syntax for, 334

SDK installation, verifying, 40SearchEngineForm.java, 192SearchEngines.java, 186–187, 190–191SearchSpec.java, 188SearchUtilities.java, 188–189SELECTED attribute, OPTION element, 636SemiRandomNumber.jsp, 349–350sendError method, 177, 182sendRedirect method, 177, 186, 197, 202, 441, 445Separate classes, writing, 91Server:

CLASSPATH, updating, 57configuring, 22–63custom URLs, assigning to servlets, 60–63downloading for our desktop, 17, 19–22port, specifying, 23SDK installation directory, identifying, 22server-specific customizations, making, 23setting up, 16–22stopping/restarting, to help debug servlets, 92URL prefix, using, 58–60WAR (Web ARchive) files, 58Web application directory, making, 56–57

index.fm Page 687 Monday, July 28, 2003 10:33 AM

Page 18: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index688

Server (cont.):Web applications, 55–63

registering with the server, 57–58Server sessions, 271–272SERVER_NAME CGI variable, 170SERVER_PORT CGI variable, 170SERVER_PROTOCOL CGI variable, 170SERVER_SOFTWARE CGI variable, 170Servet reloading, 20service method, 77–78, 170, 181, 207, 340Servlet 2.3 and 2.4 specifications, 19Servlet equivalent of CGI variables, 168–170

AUTH_TYPE, 168CONTENT_LENGTH, 168CONTENT_TYPE, 168DOCUMENT_ROOT, 168HTTP_XXX_YYY, 168PATH_INFO, 169PATH_TRANSLATED, 169QUERY_STRING, 169REMOTE_ADDR, 169REMOTE_HOST, 169REMOTE_USER, 169REQUEST_METHOD, 170SCRIPT_NAME, 170SERVER_NAME, 170SERVER_PORT, 170SERVER_PROTOCOL, 170SERVER_SOFTWARE, 170

ServletContext, 20, 430–432ServletContext-based data sharing, 430–432ServletExec (NewAtlanta), 22Servlets:

advantages of, 7–10convenience of, 8cost of, 9efficiency of, 8mainstream technology, 10portability of, 9power of, 8security of, 10

basic structure, 66–68basics of, 64–92best use of, 11debugging, 90–92life cycle, 77–86

destroy method, 85doGet method, 78–79

doPost method, 78–79doXxx methods, 78–79init method, 79–83service method, 77–78

packaging, 72–74reading form data from, 97–100

getInputStream method, 99getParameter method, 97getParameterMap method, 98–99getParameterNames method, 98–99getParameterValues method, 98getReader method, 99setCharacterEncoding method, 99–100ShowParameters.java, 104–108ShowParametersPostForm.html, 106–107ThreeParams. java, 100–104ThreeParamsForm.html, 102

role of, 3–4, 65–66servlet that generates HTML, 70–72servlet that generates plaintext, 68–69simple HTML-building utilities, 74–77SingleThreadModel interface, 86–90using to generate JPEG images:

BufferedImage class, 218–219ImageTest.java, 227MessageImage.java, 221–223non-HTML content, building, 218–219ShadowedText.html, 224ShadowedText.java, 220–221

ServletTemplate.java, 67ServletUtilities.java, 49, 75–76, 217session attribute, 362Session tracking, 262–299

associating information with a session, 268basics, 265–269browser sessions vs. server sessions, 271–272information associated with a session, looking

up, 267need for, 263–265

cookies, 264hidden form fields, 265in servlets, 265URL rewriting, 264–265

online store with shopping cart/session tracking, 281–299

catalog item implementation, 292–299CatalogItem.java, 294–295Catalog.java, 297–299

index.fm Page 688 Monday, July 28, 2003 10:33 AM

Page 19: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 689

CatalogPage.java, 281–284Checkout.html, 291–292creating the front end, 281–286ItemOrder.java, 295–297KidsBooksPage.java, 284, 285order handling, 286–292OrderPage.java, 287–291shopping cart implementation, 292–299ShoppingCart.java, 292–294TechBooksPage.java, 284, 286

servlet that shows per-client access counts, 273–276

ShowSession.java, 274–276session data, discarding, 268–269session object associated with current request,

assessing, 266–267session-tracking API, 269–271

getAttribute method, 269getAttributeNames method, 269getCreation method, 271getId method, 270getLastAccessedTime method, 271getMaxInactiveInterval method, 271invalidate method, 270isNew method, 270logout method, 270removeAttribute method, 269setAttribute method, 269setMaxInactiveInterval method, 271

URLs sent to client, encoding, 272–273user data:

accumulating a list of, 277–280OrderForm.html, 279–280ShowItems.java, 278–279

Session-based data sharing, 428–430, 456–459MVC code, 444NameBean.java, 456RegistrationServlet.java, 457–459ShowName.jsp, 458

setAttribute method, 207, 268, 344setCharacterEncoding method, 99–100setComment method, 242setContentLength method, 196setContentType method, 70, 196, 204, 218, 219Set-Cookie header, 204setDateHeader method, 196, 202setDomain method, 242

setGoesWith method, 422setHeader method, 70setHeader method, 70, 196setIntHeader method, 196setLevel method, 422setMaxAge method, 237, 242setMaxRows method, 506setNumOrdered method, 127setPath method, 243setQueryTimeout method, 506setSecure method, 243setStatus method, 176–177, 182Setup, server:

basic server configuration, checking, 40–42SDK installation, verifying, 40simple servlets, compiling/deploying, 42–49testing, 17, 39–49

setValue method, Cookie, 244setVersion method, Cookie, 244ShadowedText.html, 224ShadowedText.java, 220–221SharedCounts1.jsp, 420–421Sharing beans, 417–421

BakedBeanDisplay-application.jsp, 431–432BakedBeanDisplay-page.jsp, 424–425BakedBeanDisplay-request.jsp, 426–427BakedBeanDisplay-session.jsp, 428–430BakedBeanDisplay-snippet.jsp, 426BakedBean.java, 429BakedBeanTest.java, 430building the bean/bean tester, 422–423example, 421–432no sharing, 423–425request-based sharing, 425–427scope attribute page value, using, 423–425servletContext-based sharing, 430–432session-based sharing, 428–430

ShoppingCart.java, 292–294ShowBalance.java, 446–447ShowCGIVariables.java, 171–172ShowItems.java, 278–279ShowName.jsp, 458ShowParameters.java, 104–108ShowParametersPostForm.html, 106–107ShowPrime.jsp, 461ShowRequestHeaders.java, 150–151ShowSession.java, 274–276

index.fm Page 689 Monday, July 28, 2003 10:33 AM

Page 20: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index690

Simple servlets:compiling/deploying, 42–49

servlet that uses packages and utilities, 47–49servlet that doesn’t use packages, 43–44servlet that uses packages, 44–46

Simplified deployment method:ant tool, 52establishing, 18, 49–52IDE, and deployment, 51–52javac -d option, using, 51shortcut/symbolic link, copying to, 50–51

SIZE attribute:file upload controls, 640INPUT element, 622password fields, 623SELECT element, 635

skills parameter, 110SpeedErrors.jsp, 366–367SRC attribute, IMAGE element, 642Statement object, creating, 501, 505Store.jsp, 11StringBean class, 406–408

StringBean.java, 407StringBean.jsp, 408

StringTokenizer, 118Struts, See Volume 2Submit buttons, 626–629

NAME attribute, 626–627ONBLUR attribute, 627ONCLICK attribute, 627ONDBLCLICK attribute, 627ONFOCUS attribute, 627placing near the bottom of a form, 96VALUE attribute, 626–627

SubmitInsuranceInfo. java, 130–131SubmitResume.html, 111–112SubmitResume.java, 113–117System.out.println, 20

T

Tab order control, HTML forms, 649–650Tabindex.html, 649–650

Tag libraries, JSP, See Volume 2Tag Library Descriptor (TLD) file, 495TechBooksPage.java, 284, 286TestDatabase.java, 592–599Text areas, 624–625

Text controls, HTML forms, 620–625password fields, 623text area, 624–625text areas, 624–625textfields, 620–622

TEXTAREA element, 624–625COLS attribute, 624NAME attribute, 624ONBLUR attribute, 624–625ONCHANGE attribute, 624–625ONFOCUS attribute, 624–625ONKEYDOWN attribute, 624–625ONKEYPRESS attribute, 624–625ONKEYUP attribute, 624–625ONSELECT attribute, 624–625ROWS attribute, 624

Textfields, 620–622TextPanel.java, 393–394ThreeParams. java, 100–104ThreeParamsForm.html, 102ThreeParams.java, 330–331title attribute, jsp:plugin element, 390title request parameter, 110Tomcat, See Apache TomcatTopLink, 547Training courses, JSP and servlets, xxxiiiTransactionBean.java, 544–546Transactions.java, 543–544type attribute:

jsp:plugin element, 389jsp:useBean action, 404

U

UnknownCustomer.jsp, 453URL-decoding values, 96User access counts, cookies:

ClientAccessCount.java, 253–254tracking, 252–254

User-Agent header, 147–148, 156, 161UserIDs.java, 89

V

VALUE attribute:BUTTON element, 628check boxes, 632file upload controls, 640

index.fm Page 690 Monday, July 28, 2003 10:33 AM

Page 21: Chapter - pearsoncmg.comptgmedia.pearsoncmg.com/images/0130092290/index/0130092290_ind… · Apache Struts, See Volume 2 Apache Web server, 8, 21 ApplesAndOranges.java, 205 ApplesAndOranges.jsp,

Index 691

hidden fields, 646–647INPUT element, 621JavaScript buttons, 630OPTION element, 636password fields, 623radio buttons, 634reset buttons, 629

valueBound method, 268VBScript, 8Visual Basic, 8vspace attribute, jsp:plugin element, 390

W

wasNull method, 507Web applications, 55–63Web Design Group, 74Web farms, 9Web middleware, role of, 3, 65Web pages, building dynamically, 5–6 WebLogic (BEA), 9, 18

Web site, book, xxxiiWebSphere (IBM), 18, 91web.xml, 20, 62–63width attribute, jsp:plugin element, 390WindowUtilities.java, 395winning, big, 1–670World Wide Web Consortium, 74WrongDestination. java, 184–185WWW-Authenticate header, 195, 204

X

XML: general, 25, 60, 70, 201, 376, 391, 404, 522, 525 syntax: for JSP elements, 327, 334, 340, 370, 383 general rules, 376

Z

Zeus, 21

index.fm Page 691 Monday, July 28, 2003 10:33 AM