aspose file tools*
The moose likes Servlets and the fly likes calling servlet from java in different paths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "calling servlet from java in different paths" Watch "calling servlet from java in different paths" New topic
Author

calling servlet from java in different paths

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi

I am having a java program (sample1.java)in the path /var/lib/asterisk/agi-bin. my servlet program(sample2.java) is in another path /usr/local/apache-tomcat/webapps/voicebroadcast/WEB-INF/classes.

Is it possible to call servlet from java like

sample2 s2=new sample2();
s2.doGet(request, response);

Thanks in advance

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Where will you get the request and response implementations from?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
sorry.I dont need to get the request and response.but can i get just a string variable like

sample2 s2=new sample2();
String var= s2.campaign;
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Then how would you plan to call doGet() without a request and response?
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
yes.I didn't think about that.so, is it impossible to call the servlet from java? or any other way?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Not without implementing a servlet container yourself, which I assume is not your intention.

What is it that you are really trying to accomplish?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
If you need some business logic provided by the other servlet, then that servlet code is likely subject to refactoring. Separate the tight coupled code into separate class(es) so that you could reuse it in another (servlet) classes.

If you actually need to access the servlet by HTTP request and you need its HTTP response programmatically, then take a look for java.net.URLConnection or, a bit more enhanced, the Apache Commons HttpClient API.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling servlet from java in different paths