File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Accessing Servlet methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing Servlet methods" Watch "Accessing Servlet methods" New topic

Accessing Servlet methods

Jeremy Wilson
Ranch Hand

Joined: Feb 18, 2003
Posts: 166
How would an ejb client of a servlet, call a servlet method such as
public boolean sendFiles(String[] names, String site){

Jeremy Wilson
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well, I think the question needs to be raised about the design, more than how an EJB can call a method on a Servlet.
The big question then is why is that method in the Servlet and not in an seperate helper class that both Servlet and EJB can call? Or even in a Session EJB.
The way I always think of Servlets are work done in the service type methods, doPost, doGet, doHead, etc. They respond to a request and send stuff back, if needed. The Servlet, itself might have private methods that the Servlet needs. (Which I still think that these methods should be in a different class)
But the Servlet should not have methods that outside classes need to call.
My Opinion of course.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Scott Duncan
Ranch Hand

Joined: Nov 01, 2002
Posts: 364
Mark hit the nail on the head.
I've never done what you want to do but you should be able to instantiate the class just like any other as long as there is a constructor and then just invoke the method.

No more rhymes! I mean it!<br /> <br />Does anybody want a peanut?
I agree. Here's the link:
subject: Accessing Servlet methods
It's not a secret anymore!