wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet Calling Public Methods of Another Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Calling Public Methods of Another Servlet" Watch "Servlet Calling Public Methods of Another Servlet" New topic
Author

Servlet Calling Public Methods of Another Servlet

Steve Williams
Greenhorn

Joined: Nov 02, 2003
Posts: 3
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

Joined: Jun 08, 2002
Posts: 3178
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...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Steve Williams
Greenhorn

Joined: Nov 02, 2003
Posts: 3
Thanks Mr.Ko Ko! I used the second one. It worked!
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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

Joined: Feb 19, 2003
Posts: 147
U can use bean object.


Thanks...qingwu<br />When I open my eyes,I see your pretty face.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Calling Public Methods of Another Servlet