//package com.vistech.internet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;

public class SimpleImageLoaderServlet extends HttpServlet{

   public void doGet(HttpServletRequest req, HttpServletResponse res)
                  throws ServletException{
      try {
        res.setContentType("image/jpeg");
        ServletOutputStream out = res.getOutputStream();
        String filename = req.getPathTranslated();
        if(filename == null){
           HttpSession session = req.getSession(false);
           filename = session.getValue("imagepath")+"\\"+req.getParameter("images");
           System.out.println("filename "+filename);
           //System.out.println("path = "+ req.getServletPath());
        }
        loadImage(out, filename);
      } catch(Exception e) {System.out.println(e);}
   }
   public void loadImage(OutputStream boutstream, String filename) {
      try {
      FileInputStream bis = new FileInputStream(filename);
      byte[] imageBuf = new byte[1024];
      for(;;){
          int bytesread = bis.read(imageBuf);
          if (bytesread <0) {break;}
          boutstream.write(imageBuf,0,bytesread);
      }
     } catch(Exception e) {System.out.println(e);}
   }
}
