• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking Servlets from an XML File

 
Kerry Wilson
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a framework which contains servlet names in an xml file.( sound familiar? ) Basically, just extending the functionality of servlet registering. The only problem is I pass a child class of HttpRequestWrapper between my servlets and on the first access the InvokerServlet pass a different child class and I am getting a class cast exception. Thusly, I would like to create an initialization servlet which will create an instance of each servlet in the xml file so this error will not occur on the initial access. Any help will be greatly appreciated.
 
Atul Prabhu
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What i understand is that u want to dynamically load a servlet refering a xml file.

I think you can use

Object obj = (Class.forName("package.servlet")).newInstance();

this obj is the servlet object . You can then call the respective methods by using java.lang.reflect package.

---
Atul
 
Kerry Wilson
Ranch Hand
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this create an instance of the class that tomcat will use? Or will it still have to use the invoker servlet to create it's on when a request to one is made?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic