Reading Notes for Chapter 5, Head First Servlets and JSP

Table of Contents

147 Being a Web App 173 Writing the servlet class 200 Protext session attributes by synchronizing on the HttpSession
148 Objectives 174 Writing the Deployment Descriptor 201 The evils of SingleThreadModel
149 Kim wants to configure his email address in the DD, not hard-code it 175 There are no Dumb Questions 202 Only RequestAttributes and local variables are thread-safe!
150 Init Parameters to the rescue 176 Compile and deploy 203 Request attributes and Request dispatching
151 You can't use servlet init parameters until the servlet is initialized 177 Try it out; Troubleshooting 204 RequestDispatcher revealed
152 The servlet init parameters are read only ONCE---when the container initializes the servlet 178 The full story... (app initialization to servlet runs) 205 What's wrong with this code?
153 There are no dumb questions 179 The story continues... 206 Remembering the Listeners (answers to p. 184)
154 Testing your ServletConfig 180 Listeners: not just for context events 207 Attribute Scope (answers to p. 188)
155 How can a JSP get servlet init parameters 181 Pick the Listener 208 Code Magnets (answers to p. 161a)
156 Setting a request attribute works... but only for the JSP to which you forwarded the request 182 The eight listeners 209 Coffee Cram: Mock Exam Chapter 5 (Q1-Q2)
157 Context init parameters to the rescue 183 The HttpSessionBindingListner 210 Coffee Cram: Mock Exam Chapter 5 (Q3-Q5)
158 Remember the difference between servlet init parameters and context init parameters 184 Remembering the Listeners 211 Coffee Cram: Mock Exam Chapter 5 (Q6-Q7)
159 ServletConfig is one per servlet; ServletContext is one per web app 185 What, exactly is an attribute? 212 Coffee Cram: Mock Exam Chapter 5 (Q8-Q9)
160 There are no Dumb Questions 186 Attributes are not parameters! 213 Coffee Cram: Mock Exam Chapter 5 (Q10-Q12)
161a Code Magnets (DD for getServletContext().getInitParameter("foo");) 187 The Three Scopes: Context, Request, and Session 214 Coffee Cram: Mock Exam Chapter 5 (Q13-Q14)
161b If you see "init parameter" without servlet or context, assume servlet 188 Attribute Scope 215 Coffee Cram: Mock Exam Chapter 5 (Q1-Q2 answers)
162 So what else can you do with your ServletContext? 189 Attribute API 216 Coffee Cram: Mock Exam Chapter 5 (Q3-Q5 answers)
163 You can get a ServletContext in two different ways 190 The dark side of attributes... 217 Coffee Cram: Mock Exam Chapter 5 (Q6-Q7 answers)
164 What if you want an app init parameter that's a database DataSource? 191a But then something goes horribly wrong... 218 Coffee Cram: Mock Exam Chapter 5 (Q8-Q9 answers)
165 What she really wants is a listener. 191b Flex Your Mind (what caused the bug in Kim's code?) 219 Coffee Cram: Mock Exam Chapter 5 (Q10-Q12 answers)
166 She wants a ServletContextListener 192 Context scope isn't thread-safe! 220 Coffee Cram: Mock Exam Chapter 5 (Q13-Q14 answers)
167 Flex Your Mind (mechanism for making listener part of specific web app?) 193 The problem in slow motion...    
168 Tutorial: a simple ServletContextListener 194 How do we make context attributes thread safe?    
169 Making and using a context listener 195 Synchronizing the service method is a spectacularly BAD idea    
170 We need three classes and one DD 196 Synchronizing the service method won't protect a context attribute    
171 Writing the listener class 197 You don't need a lock on the servlet... you need the lock on the context!    
172 Writing the attribute class (Dog) 198 Are Session attributes thread-safe?    
173 Writing the servlet class 199 What's REALLY true about attributes and thread-safety?    

p147 Being a Web App

@@@

p148 Objectives

@@@

p149 Kim wants to configure his email address in the DD, not hard-code it

@@@

p150 Init Parameters to the rescue

@@@

p151 You can't use servlet init parameters until the servlet is initialized

@@@

p152 The servlet init parameters are read only ONCE---when the container initializes the servlet

@@@

p153 There are no dumb questions

@@@

p154 Testing your ServletConfig

@@@

p155 How can a JSP get servlet init parameters

@@@

p156 Setting a request attribute works... but only for the JSP to which you forwarded the request

@@@

p157 Context init parameters to the rescue

@@@

p158 Remember the difference between servlet init parameters and context init parameters

@@@

p159 ServletConfig is one per servlet; ServletContext is one per web app

@@@

p160 There are no Dumb Questions

@@@

p161a Code Magnets (DD for getServletContext().getInitParameter("foo");)

@@@

p161b If you see "init parameter" without servlet or context, assume servlet

@@@

p162 So what else can you do with your ServletContext?

@@@

p163 You can get a ServletContext in two different ways

@@@

p164 What if you want an app init parameter that's a database DataSource?

@@@

p165 What she really wants is a listener.

@@@

p166 She wants a ServletContextListener

@@@

p167 Flex Your Mind (mechanism for making listener part of specific web app?)

@@@

p168 Tutorial: a simple ServletContextListener

@@@

p169 Making and using a context listener

@@@

p170 We need three classes and one DD

@@@

p171 Writing the listener class

@@@

p172 Writing the attribute class (Dog)

@@@

p173 Writing the servlet class

@@@

p174 Writing the Deployment Descriptor

@@@

p175 There are no Dumb Questions

@@@

p176 Compile and deploy

@@@

p177 Try it out; Troubleshooting

@@@

p178 The full story... (app initialization to servlet runs)

@@@

p179 The story continues...

@@@

p180 Listeners: not just for context events

@@@

p181 Pick the Listener

@@@

p182 The eight listeners

@@@

p183 The HttpSessionBindingListner

@@@

p184 Remembering the Listeners

@@@

p185 What, exactly is an attribute?

@@@

p186 Attributes are not parameters!

@@@

p187 The Three Scopes: Context, Request, and Session

@@@

p188 Attribute Scope

@@@

p189 Attribute API

@@@

p190 The dark side of attributes...

@@@

p191a But then something goes horribly wrong...

@@@

p191b Flex Your Mind (what caused the bug in Kim's code?)

@@@

p192 Context scope isn't thread-safe!

@@@

p193 The problem in slow motion...

@@@

p194 How do we make context attributes thread safe?

@@@

p195 Synchronizing the service method is a spectacularly BAD idea

@@@

p196 Synchronizing the service method won't protect a context attribute

@@@

p197 You don't need a lock on the servlet... you need the lock on the context!

@@@

p198 Are Session attributes thread-safe?

@@@

p199 What's REALLY true about attributes and thread-safety?

@@@

p200 Protext session attributes by synchronizing on the HttpSession

@@@

p201 The evils of SingleThreadModel

@@@

p202 Only RequestAttributes and local variables are thread-safe!

@@@

p203 Request attributes and Request dispatching

@@@

p204 RequestDispatcher revealed

@@@

p205 What's wrong with this code?

@@@

p206 Remembering the Listeners (answers to p. 184)

@@@

p207 Attribute Scope (answers to p. 188)

@@@

p208 Code Magnets (answers to p. 161a)

@@@

p209 Coffee Cram: Mock Exam Chapter 5 (Q1-Q2)

@@@

p210 Coffee Cram: Mock Exam Chapter 5 (Q3-Q5)

@@@

p211 Coffee Cram: Mock Exam Chapter 5 (Q6-Q7)

@@@

p212 Coffee Cram: Mock Exam Chapter 5 (Q8-Q9)

@@@

p213 Coffee Cram: Mock Exam Chapter 5 (Q10-Q12)

@@@

p214 Coffee Cram: Mock Exam Chapter 5 (Q13-Q14)

@@@

p215 Coffee Cram: Mock Exam Chapter 5 (Q1-Q2 answers)

@@@

p216 Coffee Cram: Mock Exam Chapter 5 (Q3-Q5 answers)

@@@

p217 Coffee Cram: Mock Exam Chapter 5 (Q6-Q7 answers)

@@@

p218 Coffee Cram: Mock Exam Chapter 5 (Q8-Q9 answers)

@@@

p219 Coffee Cram: Mock Exam Chapter 5 (Q10-Q12 answers)

@@@

p220 Coffee Cram: Mock Exam Chapter 5 (Q13-Q14 answers)

@@@

 


End of CISC474 reading notes for HFSJ, Chapter 5


Valid XHTML 1.1 Valid CSS!