• Post Reply Bookmark Topic Watch Topic
  • New Topic

Make a Servlet or JSP relinquish control  RSS feed

 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I make a call to a url using a URL Conection from a Servlet1 to another Servlet2. Well, if I want Servlet2 to now have control and Servlet1 to relinquish control, how do I go about doing that.
Bascially what I got is a 3rd Party Application that handles logins. It sends a stream with info to my Servlet2. At that point I want Servlet1 to be out of the picture.
I am doing this via a browser...
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you explored the option of using the "forward" method from the RequestDispatcher? I'm not exactly sure what you mean by about half of what you typed. Is that the type of functionality you are looking for?
 
Anthony Smith
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is the deal...
I go to a url and login. That URL gets processed by Servlet1. Servlet1 sends data to Servlet2 via a Url COneection like this:
URL url = new URL("http://127.0.0.1/vp/index.jsp");
URLConnection urlc = url.openConnection();
urlc.setRequestProperty("Content-Type", "text/plain");
urlc.setDoOutput(true);
urlc.setDoInput(true);
PrintWriter pw = new PrintWriter(urlc.getOutputStream());
pw.write(xml);
pw.flush();
pw.close();
That index.jsp page just forwards to Servlet2.
Well in Servlet2 it has a RequestDispatcher usign forward, but it still goes back to Servlet 1.
Unless I put this code in Servlet 1 my browser just has a blank page:
BufferedReader br = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String msg;
while((msg = br.readLine()) != null)
{
out.println(msg);
}
That out.println(msg).. it prints the data that my servlet uses the RequestDispatcher to forward to.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!