开发者

In java servlets, how do I tell if the current request is from an include?

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜