• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet to servlet communication

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic