其实这是小弟从别处拷来的程序,然后想修改成自己想要的:
请高手帮忙看一下
picServlet.java:
package picServlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class PicServlet extends HttpServlet {  public void init() throws ServletException {
  }
  //Process the HTTP Get request
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          ObjectOutputStream picStream = null;
         try{
                FileInputStream hFile = new FileInputStream("d:/1.gif"); // 以byte流的方式打开文件 d:\1.gif
               int i=hFile.available(); //得到文件大小
               byte data[]=new byte[i];
                hFile.read(data);  //读数据
                hFile.close();                picStream = new ObjectOutputStream( response.getOutputStream());                picStream.writeObject( data );          }
         catch(IOException e){         }
         finally{
              if( picStream != null )
               {
                   picStream.flush();
                   picStream.close();
               }
         }
  }
  //Clean up resources
  public void destroy() {
  }
}DbApplet.java:package dbApplet;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.awt.*;
import javax.swing.*;public class DbApplet extends JApplet
{
        Image pic=null;
        public void paint(Graphics g){
              g.drawImage(pic,0,0,this) ;
        }       public void init()
       {
           try
            {
                 jbInit();
            }
           catch(Exception e)
           {
                 e.printStackTrace();
            }
        }
       private void jbInit() throws Exception
       {
             URLConnection  picServletConnection = null;
             ObjectInputStream picStream = null;
             URL picServletURL = null;
            try
             {
                  picServletURL = new URL( "http://localhost:8080/servlet/picServlet.PicServlet" );
                  picServletConnection = picServletURL.openConnection();
                  picStream = new ObjectInputStream( picServletURL.openStream() );
///////////////////////                  pic = (Image) picStream.readObject();//这处是自己胡乱添加的
                  MediaTracker mt=new MediaTracker(this); 
                  mt.addImage(pic,0) ;
                 try{
                            mt.waitForID(0) ;
                   }
                 catch(InterruptedException e){
                            e.printStackTrace() ;
                  }             }
            catch( MalformedURLException ee )
             {
                  System.err.println( "MalformedURLException caught!" );
                  System.err.println( ee.getMessage() );
                  ee.printStackTrace( System.err );
             }
           catch( IOException eee )
            {
                  System.err.println( "IOException caught!" );
                  System.err.println( eee.getMessage() );
                  eee.printStackTrace( System.err );
             }
           catch( ClassNotFoundException eeee )
            {
                  System.err.println( "ClassNotFoundException caught!" );
                  System.err.println( eeee.getMessage() );
                  eeee.printStackTrace( System.err );
             }     }
}
各位大哥,小弟在用////////////标记的地方之后就不会写,也就是获得图片的ObjectInputStream
我就不知道怎么办!
或者说整个程序就考虑不恰当,有错的地方请麻烦改一下,如果有相应的代码,也请贴出来,
让小弟参考参考!谢谢!