<%@page import="java.io.*"%> <% //Getting Parameters posted by the applet. //The where parameter defines whether the data have to be saved as a file //or have to be shown in a new browser window. //If the applet generated an image, it was saved in a temporary file on the //server by saveimage.jsp. In this case the filename parameter contains //the absolulte path of that file, the type do the extension. //If the applet generated a kind of text file, it is posted with the //data parameter. In this case the text file have to be saved as a file. String fname = request.getParameter("filename"); String type = request.getParameter("type"); String location = request.getParameter("where"); String data = request.getParameter("data"); //If the location is not null, and equals to "file" the image or text data //have to be saved on the client. In this case the contentType have to set // "application/zip" if(location != null) { if(location.equals("file")) { response.setContentType("application/zip"); response.setHeader("Content-Disposition", "inline; filename=marvin." + type); } } else { //In this case an image was generated by the applet, it has to be shown in //the browser window. The contentType has to be set "image/type" if(type.equals("svg")) type = "svg+xml"; response.setContentType("image/"+type); } //Getting the window's outputstream OutputStream os = response.getOutputStream(); //If data haven't been initialized - it means equals null - an image was // generated by the applet, it was saved on the server in a temporary file. //Opening the temporary file for reading, writing the image into the window's //outputstream if(data == null) { int c; FileInputStream fis = new FileInputStream(fname); while((c = fis.read()) != -1) { os.write(c); } fis.close(); //Deleting the temporary file try { File f = new File(fname); f.delete(); } catch(Exception e) { } } else { //In this case the data variable have been initialized, a text data was //generated, it has to be saved as a file. //Reading the text data, writing it to the window's outputstream PrintWriter pw = new PrintWriter(os); pw.println(data); pw.close(); } os.close(); %>