The Artima Developer Community
Sponsored Link

Java Answers Forum
how can I use POST in applet and open the result in a browser window?

1 reply on 1 page. Most recent reply: Oct 3, 2002 7:26 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Peng Zuo

Posts: 1
Nickname: ageen
Registered: Oct, 2002

how can I use POST in applet and open the result in a browser window? Posted: Oct 2, 2002 8:38 PM
Reply to this message Reply
Advertisement
HI,

Is there any way to do this:

In applet, using POST method to a URL, and grap
the returned data and display in a browser window?

Thanks,
Peng


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: how can I use POST in applet and open the result in a browser window? Posted: Oct 3, 2002 7:26 PM
Reply to this message Reply

try{
String urlPrefix = "http://127.0.0.1:8080/Servlets/YourServlet";
String query = URLEncoder.encode("name", "8859_1") + "=" + URLEncoder.encode("John Smith", "8859_1");

URL url = new URL(urlPrefix);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
OutputStream bos = new BufferedOutputStream(os);
OutputStreamWriter osw = new OutputStreamWriter(bos, "8859_1");
osw.write(query + "\r\n");
osw.flush();
osw.close();

String response = "";
InputStreamReader isr = new InputStreamReader(new BufferedInputStream(connection.getInputStream()));
int c = 0;
while ((c = isr.read()) != -1){
response = response + String.valueOf((char)c);
}
JOptionPane.showMessageDialog(null , response);

}catch(MalformedURLException murle){
System.err.println("MalformedURLException: " + murle.getMessage());
}catch(IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
}

Flat View: This topic has 1 reply on 1 page
Topic: An Array of Test Entry Boxes Previous Topic   Next Topic Topic: AAAAHHHH Not working

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use