Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes How to call servlet before each jsp request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to call servlet before each jsp request" Watch "How to call servlet before each jsp request" New topic
Author

How to call servlet before each jsp request

bhavin pandya
Greenhorn

Joined: Jan 21, 2006
Posts: 2
Hello Friends,

What I want to do is before request goes to any of my jsp i want to call one servlet.

I am planning to check cache in that intermediate servlet ..
if the requested jsp is already cached then that servlet only print the content from cached file.
otherwise it will make url call to the requested jsp in background and will generate the cache file also.
so that it can be useful for next request.

One way to do this is ,... changing the url like this.

Existing URL: http://myserver.com/application/jspname.jsp&id=userid
New URL: http://myserver.com/application/myservlet?page=jspname&id=userid

but for this I need to change path in my whole application.

Isnt it possible through any configuration changes ?

Please suggest me some other way...

Thanks in advance.
Bhavin Pandya
Michael Duffy
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Originally posted by bhavin pandya:
Hello Friends,

What I want to do is before request goes to any of my jsp i want to call one servlet.

I am planning to check cache in that intermediate servlet ..
if the requested jsp is already cached then that servlet only print the content from cached file.
otherwise it will make url call to the requested jsp in background and will generate the cache file also.
so that it can be useful for next request.

One way to do this is ,... changing the url like this.

Existing URL: http://myserver.com/application/jspname.jsp&id=userid
New URL: http://myserver.com/application/myservlet?page=jspname&id=userid

but for this I need to change path in my whole application.

Isnt it possible through any configuration changes ?

Please suggest me some other way...

Thanks in advance.
Bhavin Pandya



Sounds more like a Filter to me. Why not register a Filter in your web.xml? You can even tailor it to be applied only to certain URLs that way.


%
 
jQuery in Action, 2nd edition
 
subject: How to call servlet before each jsp request