web程序中,客户端向服务器上传音乐或图片的时候怎搞??
 哥们,
 给俺来段有注释的代码,谢过!

解决方案 »

  1.   

    TestForm myform = (TestForm) form;
    try{
                FormFile file=myform.getTheFile();
                InputStream stream=file.getInputStream();
                String filename=getServlet().getServletContext().getRealPath("/")+file.getFileName();
                OutputStream bos=new FileOutputStream(filename);
                int byteRead=0;
                byte[] buffer=new byte[8192];
                while((byteRead=stream.read(buffer,0,8192))!=-1){
                      bos.write(buffer,0,byteRead);
                 }
                 bos.close();
                 myform.setMybeanvariable1(filename);
                }catch(IOException ioe){
                
                     return null;
                }   上述中,第一行form为ActionFrom类型的,也就是用struts格式写成的上述代码,你可以看一下这个上传文件的格式,也就可以用在你的上面啦,想得到这个全部的内容,你可去我的资源中下载呀,这个文件名是:文件代码上传            
      

  2.   

    不晓得你要做成什么样的效果,好像音乐和图片跟上传其它的东东没什么区别吧
    web程序在上传的时候音乐和图片都是以二进制流的形式发送到服务器的,可以用现成的组件,当然自己解析也不麻烦