ViewFile.javaAPI DocExample1076Thu Apr 05 01:27:18 BST 2001None


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 because 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());