前台页面
图片<input type="file" name="path" size="29">action类
public String getPath() {
     return path;
}
public void setPath(String path) {
     this.path = path;
}
FileInputStream in = null;
try {
in = new FileInputStream(this.getPath());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}   
Blob photo = null;
try {
photo = Hibernate.createBlob(in);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}我在自己的电脑上可以获得图片路径并将图片保存到数据库
但在局域网其它机器上登陆页面并向数据库插入图片时报下面的错误
java.io.FileNotFoundException: D:\My Documents\My Pictures\1024x768.jpg (系统找不到指定的文件。)

解决方案 »

  1.   

    建个ActionForm,使用formfile去接数据,顺便设置form的enctype=multipart/form-data
      

  2.   

    String path=ServletActionContext.getServletContext().getRealPath("/fileDir");
    path=path+fileName;
    System.out.println(myFile);
    try {
    BufferedInputStream input=new BufferedInputStream(new FileInputStream(myFile),2048);
    BufferedOutputStream output=new BufferedOutputStream(new FileOutputStream(new File(path)),2048);

    byte [] b=new byte[2048];
    while(input.read(b)>1){
    output.write(b);
    b=new byte[2048];
    }

    input.close();
    output.close();
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

    把图片存到文件夹里面  数据库里面存路径 
    上面给你个例子  存到文件夹里面
      

  3.   

    1楼说的对,我应该把path定义为File类,问题以解决,谢谢各位