Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Know which servlet is sending the request

 
sreeni san
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ed Ward
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In ServletC, why not just use HttpServletRequest.getRequestURI() ?
There is no need to set a "flag" before forwarding is there?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic