Feb. 27th, 2007

juan_gandhi: (Default)
When you, like me, switch from using JSP everywhere to writing servlets that call some rendering widgets, you'll soon discover one simple thing: you'll have to pass around Request and Response. Your servlet works as a small server, not as something that serves one specific request, with the ability to reference, when necessary, session and global data.

What do you do if you want to store and pass around request data? There are two ways: a) add an attribute to the current request, and b) use ThreadLocal - so that your variable looks global, but is attached to the current request.

is it object-oriented? No, it is not. Your servlet code behaves as if it were a "utility function". Pass parameters, output results. Looks a little bit monadic, but not object-oriented.

And why do we need a hundred of various servlets? Just because we store request-specific code right there, in the servlets. Why not subclass a request; figure out the type of the request, use abstract factory to retrieve a specific factory that produces specific request-handling instance, with all the data right inside that instance? Then you would not need so many servlets. You will actually need just one servlet.

Ever saw a server that has just one servlet? Check out industriallogic.com. They have just one servlet. How do I know? I had asked Josh.

Now details.
Read more... )

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
181920 21222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2025 01:26 pm
Powered by Dreamwidth Studios