aspose file tools*
The moose likes Servlets and the fly likes Know which servlet is sending the request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Know which servlet is sending the request" Watch "Know which servlet is sending the request" New topic
Author

Know which servlet is sending the request

sreeni san
Ranch Hand

Joined: Aug 14, 2001
Posts: 39
Hi

I am calling ServletC from ServletA and ServletB.

Is there a way to know as to which servlet sent the request.
In other words,

In ServletC, I would like to know which Servlet ( ServletA or ServletB) sent the request.

The URL call from both ServletA and ServletB to ServletC will be the same.

Thanks,
Santosh
Manesh Kumar
Ranch Hand

Joined: Mar 21, 2006
Posts: 94
You can set some flag in Request scope before forwarding the request to another servelt.

Another option is Http Referer which will work only from client side request.


Manesh
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
In ServletC, why not just use HttpServletRequest.getRequestURI() ?
There is no need to set a "flag" before forwarding is there?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by S Root:
In ServletC, why not just use HttpServletRequest.getRequestURI() ?
There is no need to set a "flag" before forwarding is there?


I think the original poster was more interested in knowing where the request came from.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by sreeni san:

Is there a way to know as to which servlet sent the request.
In other words,


Servlets don't send requests, browsers (or other web clients) do.
Browsers don't know that the page which is currently loaded is the result of servlet (or JSP page, or PHP page, or ASP....).

In other words, unless you add something to the link or form that will be used to generate the next request, the server will have no way of knowing how the previous page was built.
The referer header only tells you what the URL for the last page was.
In J2EE apps this isn't always helpful. Servlets and JSPs often have url-mappings that have nothing to do with the actual servlet names.

If this is important to you, follow Dilip Kumar Jain's advice and add a hidden form field or query string variable to each form/link in your app.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Know which servlet is sending the request