tags:

views:

33

answers:

2

From within a servlet, how can I tell if the servlet is being called by a RequestDispatcher("").include, or if it was called normally?

+2  A: 

There should be a bunch of request attributes present, listed here:

http://www.caucho.com/resin-3.0/webapp/faq.xtp#forward-path

For example, request.getAttribute("javax.servlet.include.request_uri") should return a non-null value if an include is in progress.

skaffman
Thanks, just tried it out and it worked perfectly :)
Kyle
A: 

I'm not sure you can tell directly in a request object, however you can (in servlet 2.4+) insert Filters based on whether the request was a request, a forward, or an include with a declaration in your web.xml.

The setup is described on this developerworks article.

You could, for example, use this technique to intercept includes destined for the URLs you are interested in, and add an attribute to the request which you could then see in your servlet.

Brabster