File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Calling Public Methods of Another Servlet

 
Steve Williams
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 servlets. One servlet uses a parser to parse XML. Then this servlet stores parsed data on a data structure (Vector). This servlet needs to pass this Vector to another servlet- this servlet controls a database. Or, conversely, this second servlet needs to get the Vector from the first servlet.
I even tried using the deprecated getServlet() method but still I couldn't get it to run.
Any other ways of doing this? How else could one servlet use a public method of another servlet?
Thanks in advance. Code snippets would be very much appreciated.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to share the data between servlets.
1. Use getServletContext to get an object of web aplication context and use setAttribute to share application-wide data.
2. Declare the first servlet variable and use that object in the second servlet.
There may be more ways to solve your problem... I got above two solutions...
Hope they work...
 
Steve Williams
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mr.Ko Ko! I used the second one. It worked!
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah Steve, sometimes some programmers overlook such kind of fundamental things...
It's glad to hear that your servlets are working well...
 
qingwu wang
Ranch Hand
Posts: 147
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U can use bean object.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic