Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet to servlet communication  RSS feed

 
Sunil Kumar B A
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I require to move from one servlet to other servlet based on certain criteria. I came across two ways to do this:
1. Using URL http://.../servlet/<package.name>.ServletName
2. Using RequestDispatcher

The first way of accessing a servlet is not recommended because of certain issues like security, managablity etc.

The second way of using RequestDispatcher is preferred. However, to access the servlet using this method, it is required to use the url pattern of the servlet which has to be accessed (if I'm not wrong) in the web.xml file. There is a problem with this, as the developer should decide the url pattern initially. By doing this the deployer has to make sure he maintains the same url pattern; failing to which the code has to be changed to alter the url pattern.

Now, my question is, is there any other better way for enabling servlet-to-servlet communication, rather than avoiding it?
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i don't have an answer for your question
as the developer should decide the url pattern initially. By doing this the deployer has to make sure he maintains the same url pattern;

isn't it the same case with every servlet... i.e to maintain the same url pattern in the web.xml
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36396
453
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil,
Welcome to JavaRanch!

Even with approach #1, you have to decide what the name of the servlet will be and not change that. And I don't recommend approach #1. RequestDispatcher is the standard way to go about this.
 
Sunil Kumar B A
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys.

Hard-coding the Servlet name is different from hard-coding the url-pattern. The developer decides the Servlet name and the deployer decides the url-pattern for that servlet. By hard-coding the url-pattern, wouldn't there be problem with maintainability?

My concern is, by hard-coding the url-pattern, aren't we compromising the "separation of concern" between developer and deployer?
 
Vinod K Singh
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil Kumar B A wrote:My concern is, by hard-coding the url-pattern, aren't we compromising the "separation of concern" between developer and deployer?

Usually such communication is required in applications containing both of the servlets. In such scenarios the line between developer and deployer is very thin, almost always both are same. Though this concern will be valid when one servlet is bundled as a library. To overcome such situations pass the url pattern as parameter in web.xml.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil Kumar B A wrote:Thank you guys.

Hard-coding the Servlet name is different from hard-coding the url-pattern. The developer decides the Servlet name and the deployer decides the url-pattern for that servlet. By hard-coding the url-pattern, wouldn't there be problem with maintainability?

My concern is, by hard-coding the url-pattern, aren't we compromising the "separation of concern" between developer and deployer?


The deployer is responsible for the configuration of the deployment environment. However, if they are allowed to arbitrarily select their own names for servlet mappings, the application will certainly not function. As the developer, you need to tell the deployer what you need the servlet mapping to be. The deployer is responsible for figuring out how to achieve this in the deployment environment.

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!