• Post Reply Bookmark Topic Watch Topic
  • New Topic

URLConnection & writing HTML back to browser  RSS feed

 
Medha kamat
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i am trying to call a servlet from a swing component.This servlet then returns a html(with help of PrintWriter) which shold be displayed in a new browser window.
I am successful in calling a servlet from a swing componenet using URLConnection class.I am also
geting html back ..problem is how to display this html in a new browser window.
here is my code
URL url = new URL("http://../myServlet");
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
DataInputStream in =new DataInputStream(connection.getInputStream());
String line;
StringBuffer result = new StringBuffer();
while(null != ((line = in.readLine()))){
//debug line to find out about html code
System.err.println(line);
result.append(line + "\n");
}
in.close();

So what am i doing wrong here..am i missing something?How do i display this output in a browser?
Please help as i am struggling over this code..
Thanks
Medha Kamat
 
raimondas zemaitis
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what browser you want to display this in ? System default ? In that case save html to a file with extension html and call external process via Runtime.exec(). If system has default browser set, it should launch it and load your file.
 
Medha kamat
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for the reply.
That's where the whole problem is.Before i had entirely different approach where my java objects were creating html file and then with the help of Runtime.exec() i managed to open this html file in a browser but it openes this html in a available browser window.(and not a new browser window which is essential requiremnet of user)
Do u know how to display html in a new browser window with Runtime.exec()..if u know it that would be great help.
Just a bit on what i am trying to do..
I have swing component i want when user clicks on one of the menus he/she should get result in a new browser window.The way i got it worked is i get to display result in a browser but Runtime.exec opens it in a existing browser window..
Well one more thing this is not a Applet.If it would have been a Applet i know the solution.(showDocument method of a AppletContext )

Any thaughts on this ..and i will be delighted.
Thanks
Medha
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!