• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To call a servlet from another servlet

 
Nathan KV
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic