Subir un fichero desde un applet hacia un servlet

2843 vistas

Lado applet:



java
  1. URL urlservlet = new URL("http://localhost:8080/imed/ImageMapServlet");
  2. HttpURLConnection connExtension = (HttpURLConnection)urlservlet.openConnection();
  3.  
  4. in.read(tableauImage);
  5. in.close();
  6.  
  7. HttpURLConnection connImage = (HttpURLConnection)urlservlet.openConnection();
  8. connImage.setDoInput(true);
  9. connImage.setDoOutput(true);
  10. connImage.setUseCaches(false);
  11. connImage.setRequestProperty("Content-Type","application/octet-stream");
  12. DataOutputStream out = new DataOutputStream(connImage.getOutputStream());
  13. out.write(tableauImage, 0, tableauImage.length);
  14. out.flush();
  15. out.close();



Lado servlet:



java
  1. // Recuperación del flujo entrante
  2. java.io.DataInputStream dis = new java.io.DataInputStream(request.getInputStream());
  3. dis.readFully(temp);
  4. dis.close();
  5.  
  6. // Escritura del fichero imagen sobre el servidor
  7. File objServidor = new File("/directorio/nombrefichero");
  8. FileOutputStream fos = new FileOutputStream(objServidor);
  9. fos.write(temp);
  10. fos.close();