Need to make a website for a school project.
Decided to make a website like photobucket.

I got every page read, but the only thing missing is the uploading part.
Does anyone know where I can find some examples of uploading blobs?
Or mayb someone can share one.
The thing is that the pictures will need to be stored in the database, and that's causing most of the problems.
The storing and retrieving part.

I pref. not to use servlets, since I will need to explain the code afterwards, and normally a servlet contains a lot more code.

<%                        
        String pathoffile="";
        String savepath =application.getRealPath("\\")+"\\Userimage\\";
        String filename = "";
        ServletInputStream in = request.getInputStream();
        byte line[] = new byte[128];
        int i = in.readLine(line, 0, 128);
        int boundarylength = i - 2;
        String boundary = new String(line, 0, boundarylength);
        while (i != -1) 
        {
            String newline = new String(line, 0, i);
            if (newline.startsWith("Content-Disposition: form-data; name=\"")) 
            {
                String s = new String(line, 0, i - 2);
                int pos = s.indexOf("filename=\"");             
                if (pos != -1) 
                {
                    String filepath = s.substring(pos + 10,s.length()-1);
                  pathoffile=filepath;
                    pos=filepath.lastIndexOf("\\");
                    if(pos!=-1)
                    {                                               
                        filename=filepath.substring(pos+1);                         
         filename=filename.replaceAll(" ","_");               
                    } 
                    else 
                    {                         
                     filename = filepath;
                    }
                } 
                else 
                {
                   break;
                }
            //this is the file content
            i = in.readLine(line, 0, 128);
          //System.out.println("1 READING OF I="+i);
            i = in.readLine(line, 0, 128);
            //blank line
            i = in.readLine(line, 0, 128);
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            newline = new String(line, 0, i);
            while (i != -1 && !newline.startsWith(boundary)) 
            {
                 //System.out.println("I!=-1 AND NEWLINE NOT STARTS WITH BOUNDARY I="+i);
                //the problem is the last line of the file content
                //contains the new line character
                //so,we need to check if the current line is
                //the last line.
                buffer.write(line, 0, i);
                i = in.readLine(line, 0, 128);
                newline = new String(line, 0, i);
            }
            try 
            {
                //save THE UPLOADED FILE
                String temp=filename;
                filename=id+temp;
                RandomAccessFile f = new RandomAccessFile(savepath + filename,"rw");
                byte bytes[] = buffer.toByteArray();
                f.write(bytes, 0, bytes.length - 2);
                f.close();
            } 
            catch (Exception e) 
            {
               System.out.println(e);  
            }
        }
        i = in.readLine(line, 0, 128);       
    }//end while                      
   %>

Thanks a lot, but could you also say what lib's I need to import?
It gives me:
Cannot find symbol
location: class SimplifiedJSPServlet

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.