网上找的一个小例子
public String uploadImage(InputStream  Images){

WebContext webContext=WebContextFactory.get();
String saveurl=webContext.getHttpServletRequest().getSession().getServletContext().getRealPath("/image/goods_pic");
File file=new File(saveurl+"/"+"wo"); try {
int available=Images.available();
byte[] b=new byte[available];
FileOutputStream foutput=new FileOutputStream(file);
Images.read(b);
foutput.write(b);
foutput.flush();
foutput.close();
Images.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}    return "图片上传成功!";
}java参数是InputStream类型,那么js里面怎么写呢?
var images = dwr.util.getValue('up');
 upload.uploadImage(images,msg);  
 up是<input type="file">的name属性名,msg回调函数,这样子不行,会报错: message[java.lang.IllegalArgumentException: Missing method or missing parameter converters: upload.uploadImage] ,应该是数据类型不匹配吧?那么应该怎么写呢?或者是在dwr.xml里面配置那个converter吗?我只想用dwr,其他方法不考虑。

解决方案 »

  1.   

    dwr不能上传文件
    或者说ajax不能上传文件
      

  2.   

     啊,不会吧,dwr不就是用js去访问java里的方法吗。只要能把参数传过去不就行了吗
      

  3.   

    一楼白坑人了http://directwebremoting.org/dwr-demo/simple/upload.htmldwr官网上传例子
      

  4.   

    这个我也看了,不过他好像并没有把图片保存到服务器上,我不知道该怎么保存。
    不过既然他能对BufferedImage uploadImage操作,我为什么不行?js很相似啊
      

  5.   

    呵呵,曾经尝试dwr直接上传文件过未果,后来就一直以为不行了,抱歉抱歉