How do i find out whether a request to a particular servlet is coming from another servlet or, if it is coming from a user request?

Christopher Schultz

[While it is tempting to use request.getRemoteHost, this will not work.] The getRemoteHost should always return a foreign IP address. The only reason you might get the local host as your IP from getRemoteHost is if your servlet actually made an HTTP request to another servlet.

To answer the original question, you can use a standard way to notify servlets further-down the 'forward-chain' that they have been forwarded-to by placing an object in the request 'attributes'. Each action can check this attribute against, say, null, and if it is non-null, then it can assume that it was a forward from another servlet, not an original request from a client's browser.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact