FileDocCategorySizeDatePackage
ViewFile.javaAPI DocExample1208Tue Jan 25 10:45:14 GMT 2000None

ViewFile

public class ViewFile extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    // Use a ServletOutputStream since we may pass binary information
    ServletOutputStream out = res.getOutputStream();

    // Get the file to view
    String file = req.getPathTranslated();

    // No file, nothing to view
    if (file == null) {
      file = getServletContext().getRealPath("/index.html");
    }

    // Get and set the type of the file
    String contentType = getServletContext().getMimeType(file);
    res.setContentType(contentType);

    // Return the file
    try {
      ServletUtils.returnFile(file, out);
    }
    catch (FileNotFoundException e) {
      log("Could not find file: " + e.getMessage());
      res.sendError(res.SC_NOT_FOUND);
    }
    catch (IOException e) {
      getServletContext().log(e, "Problem sending file");
      res.sendError(res.SC_INTERNAL_SERVER_ERROR, 
                    ServletUtils.getStackTraceAsString(e));

    }