struts self-quiz

Q: what kind of obj is returned by execute()? How is it related to the httpRequest’s forward() call?
Q: how does execute() get the form input data? P741
Q: how many servlets are there in a typical web app? how many are there in a struts app? P743
Q: a session is for one web app only?
Q: how 2 share a session obj btw 2 web apps?


servlet filters — possible uses

usage: add custom headers. both request and response. custom headers are flexible and powerful communication devices. X-ZED headers.

usage: standard logging on selected requests. You can add this filter to any number of servlets.

usage: time logging. end-to-end roundtrip
usage: request translation. response too.
usage: response compression
usage: consistent cookie processing and logging
usage: authentication and single-sign-on
usage: consistent look and feel?
usage: spell checker?

2 ways for http sessions to share a single object

2 ways for sessions to share a single huge object

Requirement: a huge object to be instantiated before the first session, and kept alive after all sessions end. Object is not immutable.

Solution 1: put that object in an app-scope bean.

Solution 2: static field in a special class. Your huge object will be reachable from the persistent class-object.

%%struts quiz

brief points? ok
j4: keep for review in 2 years

[g=generic servlet/jsp issue]

  1. [i] error-handling is relatively simple but imp2iview. What kind of entities read ActionErrors and how are they used? views?
  2. ActionForward ^ ActionForwards ? P 113
  3. where does Struts use reflection and introspection? P 114
  4. do you need to manage sessions or struts does it for you?
  5. [i] what kind of data structure to hold multiple errors in ActionErrors (No need to be exact) ?
  6. how2get an afbean from a mapping object? Is the afbean “contained” (HAS-A) in the mapping obj? I think when the afbean object exists in JVM, the mapping obj provides a path to it.
  7. [gi] when does a session start and in which method? probably by ActionServlet
  8. [i] signature and usage of findForward()? defined in which class? P 741 [[ ?? ]]
  9. [gi] is ActionServlet a singleton?
  10. which object invokes the afbean’s validate()?
  11. how does execute() retrieve the afbean? from the argugment mapping obj or from the request argument?
  12. how2get formbean from req? when ? when req is forwarded to a non-struts servlet or another struts servlet?
  13. [i] which method(s) return ActionErrors (see the trailing s), following which well known design pattern?
  14. let’s zoom into Struts’ usage of dataSource class in standard java. which struts components interact with a datasource?
  15. [g] is ActionServlet a single-threaded servlet, and need many sisters to service simultaneous requests?
  16. [gi] How is ActionServlet thread-safe?
  17. session in struts is same as session in other servlets?
  18. <action input=…. means?
  19. <action name=…. means?
  20. struts connection pooling? no answer
  21. beside global forward and local forward, there’a 3rd way to DEFINE an afward. P189
  22. which validator xml file contains the javascript function? What’s the other major content in the samel xml? name of a method?
  23. controls the (non-validator) validate() method u create in your afbean, but what if u use validator?
  24. 1 basic use of var in validator.xml? p378
  25. #1 most basic validator in the validator package? how do u configure it in validator-rules.xml? p375
  26. aforward obj is returned by which method to whom? How is it used?
  27. [gi] in which method do u do jdbc connect? perhaps a M object not defined by struts
  28. why execute() need the map? local forwards?
  29. g how does a non-struts servlet retrieve afbean from the request (received by forward)? P221
  30. Without struts-validator, what page is returned to browser upon validation error? How do u make this takes place by configuration?
  31. biggest 2 struts extensions each can be used outside struts, and each defines its taglib. What’re the 2 tag prefixes?
  32. what return type do u use with a formbean getAmount() ? P155
  33. simple yet important AR question: which obj calls execute()? P 741
  34. where 2 spell out a regex? how 2 pass it into a validator
  35. can take one of 3 { include, forward, ???? } I think it’s type
  36. ignore validator for now. afbean usually defines an public instance method validate(). what’s the signature? revealing! P740
  37. [i] simple yet tricky question: exactly which object (loaded into the servlet container) acts as the router, inspecting and dispatching requests to other objects?
  38. signature of execute(). AR-revealing
  39. [gi] how does the query result get into the view? aforward? req obj? P 741 [[servlet]]
  40. [i] which obj auto-populates a formbean? ActionServlet?
  41. where is the Model object instantiated? P 741 [[ servlet ]]
  42. is the mysterious but important ActionServlet (full class name) mentioned in any prominent place? Hint: along with struts-config.xml. P 743 [[servlet]]
  43. during request processing flow, describe when the mapping object is loaded and how it controls each module such as form population/valiation, forward, custom action etc. P47.
  44. example of httpSession in struts? P79

property^param^attribute ] servlet

property = field
attribute => 4 scopes
param … usually means GET or POST params
These are the shortest intro to the 3 frequent terms in servlet/jsp literature. Now some details.
— param
GET => query string
POST => user input
usually means “request param” ie GET/POST param, unless otherwise stated
means request param, too!
disambiguation: “parameter” and “param” sometimes have specific and different meanings.
— attribute is a servlet concept
is usually a bean

corresponds to the setAttribute() and getAttribute() methods

in EL, ${*} usually refers to an attribute “abc”

disambiguation: Some servlet literature talks about “attribute” when they mean “xml attribute”.
–property => HAS-A.
Can be a bean.
is a generic java concept.
HAS-A can be nested, so can properties.
“setProperty” => a field in a bean

INCLUDE <jsp:include> <c:import>

The 2 common alternatives are INCLUDE and .

, defined in jstl-core, is less common.

To memorize the key difference among the 3 alternatives, #1 thing to remember is

” is in the middle ground”

reads content from arbitrary URL (vs which is restricted to the jvm)
* Insert into page
* Store in variable

getRequestDispatcher() in 2 classes

A: There is very little difference between the ServletContext and ServletRequest versions of this method, the RequestDispatcher you get operates in exactly the same way. However, the ServletRequest method also allows you to use a path argument that is relative to the “current” resource, starting with “./Example.jsp” or “../Example.jsp”. The ServletContext getRequestDispatcher method should only be used for paths relative to the application root, starting with “/Example.jsp”.

pretend2b d controller – [[headfirst servlet]]

The Most vague concept is the intangible Model. (New discovery: P 741, 745 [[ servlet ]] has a simple, clear example )

One excellent starting point is a real, tangible, mapping file.

Another starting point (P733 [[ servlet ]]) is “pretend to be the contoller” and trace its steps. You will notice that mostly the controller deals with
* request obj and stuff put in there such as user inputs
* response obj containing query output
* views
* query input, query output, to be sent to the view

After these things become familiar, maybe u can then lj the interactions with the elusive Model. Maybe there’s no model. Maybe it’s just a term used by … some people. Maybe it’s well defined in GUI.