Applet y servlet
Publicado por Hector (27 intervenciones) el 11/07/2007 11:02:47
Wenas, a ver tengo una duda, tengo un applet en una pagina html que manda una peticion a un servlet y este le manda una pagina html.
Hay alguna manera de abrir esa pagina en una ventana nueva en la parte del servlet?
Yo lo consigo asi:
InputStream respuesta = serverCon.getInputStream();
String pagina = recibirRespuesta(respuesta,serverCon);
getAppletContext().showDocument(new URL("file:///"+pagina), "_blank");
el metodo recibir respuesta es este:
public String recibirRespuesta(InputStream in, URLConnection con ) throws IOException {
byte[] buf = new byte[1024];
File paginaCreada = new File("D:\\pagina.html");
FileOutputStream fos = new FileOutputStream(paginaCreada);
try {
int len = 0;
while ((len = in.read(buf)) > 0) {
fos.write(buf, 0, len);
}
in.close();
fos.close();
} catch (IOException e) {
try {
/(HttpURLConnection) con).getResponseCode();
InputStream es = ((HttpURLConnection) con).getErrorStream();
int ret = 0;
// read the response body
while ((ret = es.read(buf)) > 0) {
}
// close the errorstream
es.close();
} catch (IOException ex) {
// deal with the exception
}
}
return paginaCreada.getAbsolutePath();
}
Hay alguna manera de abrir esa pagina en una ventana nueva en la parte del servlet?
Yo lo consigo asi:
InputStream respuesta = serverCon.getInputStream();
String pagina = recibirRespuesta(respuesta,serverCon);
getAppletContext().showDocument(new URL("file:///"+pagina), "_blank");
el metodo recibir respuesta es este:
public String recibirRespuesta(InputStream in, URLConnection con ) throws IOException {
byte[] buf = new byte[1024];
File paginaCreada = new File("D:\\pagina.html");
FileOutputStream fos = new FileOutputStream(paginaCreada);
try {
int len = 0;
while ((len = in.read(buf)) > 0) {
fos.write(buf, 0, len);
}
in.close();
fos.close();
} catch (IOException e) {
try {
/(HttpURLConnection) con).getResponseCode();
InputStream es = ((HttpURLConnection) con).getErrorStream();
int ret = 0;
// read the response body
while ((ret = es.read(buf)) > 0) {
}
// close the errorstream
es.close();
} catch (IOException ex) {
// deal with the exception
}
}
return paginaCreada.getAbsolutePath();
}
Valora esta pregunta


0