Re: counts the number of hit on a website containing many JSPs
Garg <sendtog...@gmail.com> wrote:
Thanks John for your input. But i [sic] can't implement this because it
needs a lot of code change.
Awww, that's really tough.
That is a pitiful excuse for not doing necessary work. It might
justify delaying it, but it isn't a good reason to stop altogether.
It's especially bad if your application happens to be badly designed
(not that yours is, but if). The work necessary to fix the problem
will only get bigger and bigger, until finally the whole thing
collapses and you have to make the changes anyway, only by then it'll
be orders of magnitude harder.
It's also tough if you cannot deliver the desired functionality
without the code changes, and you won't make the changes because
they're too extensive. What do you do then?
servlet life cycle says that init or service method of the servlet
will be called whenever you call for the servlet. Can't i [sic] do something
Not quite. The 'init()' method is called when the servlet is loaded,
which might be once for many, many requests. The service() method is
just the doPost() and doGet() methods, in effect, so you're already
coding it.
so i [sic] can put a layer before init or service method and that layer will
Others have already suggested filters for you. Did you look into
that? It's pretty much just what you're describing. (Except of
course it only applies to the service() method, not the init()
method.)
increment the count or check any necessary thing like authentication
if i [sic] need to do that.
I thought you said this app didn't have authentication?
In any event, filters will be one way.
Do not be afraid to rewrite. If it's the quickest way forward, then a
slower way will not get you there faster.
--
Lew