wood burning stoves 2.0*
The moose likes Servlets and the fly likes To call a servlet from another servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "To call a servlet from another servlet" Watch "To call a servlet from another servlet" New topic
Author

To call a servlet from another servlet

Nathan KV
Greenhorn

Joined: Aug 09, 2001
Posts: 25
Hai all,
I just want to know how to call a servlet from another servlet through program (not through browsers).
Eg:-
I want to call http://100.101.12.89:7001/SecondServlet from
http://100.101.12.89:7001/FirstServlet
And also please tell me, how to call the https://100.101.12.89:7002/SecondServlet from
https://100.101.12.89:7002/FirstServlet
I come to know that using URLConnection it is possible. But please tell me how ?
And i am using Weblogic 6.1.
Regards
Nathan

[ May 09, 2002: Message edited by: Nathan KV ]
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
there are 3 ways to use servlet chaining:
1 is to use the :
repsonse.sendRedirect("URL here");
thats causes the browser to redirect to the new url or in this case servlet.
i think this is what u want.
second involves forwarding the request and response to another servlet, but in this case you need to male sure the first servlet didnt produce any output or it wont work.
request.getRequestDispatcher("URL here").forward(request,response);
third is almost the same but you actually include the output of the second servlet in your first one:

request.getRequestDispatcher("URL here").include(request,response);
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Calling another servlet through URLConnection from a servlet is just like calling it from an applet or an application. I think there were some recent threads on communication from an applet to a servlet, search for those.
Bukk
Nathan KV
Greenhorn

Joined: Aug 09, 2001
Posts: 25
Hi All,
Thank you very much for your reply.
Now that I am not able to post the values from one servlet to another through https using URL connection and I also need to know whether I could redirect the response to another servlet.
The reason is I could post the values to a servlet from normal java program through https using URL connection, but in this case also I am not able to redirect the response to another servlet.
Could you help me in finding out the problem of posting the values one servlet to another through https using URL connection and redirecting the response too.
Thanks in Advance,
Nathan.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
You can certainly fake a POST - you just have to have the request headers and body content right.
IMHO the best way to start is to trap the content of a normal POST from a browser so you can see what you have to send.
I wrote a utility to snoop on browser request/server response data. There is a link to UtilSnoop download at the bottom of this page:
http://www.lanw.com/books/javasoap/
Bill
 
 
subject: To call a servlet from another servlet
 
Similar Threads
Session Lost
getting HTTP Status 404 - /servlet/Firstservlet error in Tomcat
port 7002
Anyone has weblogic/wasp expertise?
problem with the url..