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


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) {
      out.println("No file to view");

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

    // Return the file
    try {
      ServletUtils.returnFile(file, out);
    catch (FileNotFoundException e) { 
      out.println("File not found");
    catch (IOException e) { 
      out.println("Problem sending file: " + e.getMessage());