Try:
request.getHeader("referer");
You can also create a hidden field in the form, and then use the if statement to check and route accordingly.
I would recommend you use a hidden field. Although this is certainly more of a hassle, it is also more reliable. The abstract field can be removed from the HTTP header by the proxy server. In fact, the browser does not need to send the referer field to the header at all.
See a good discussion here . The above explanation is an excerpt from this discussion.