有没有DWR的高手 啊关于利用dwr上传文件的问题

FXZ555 2012-08-13 02:35:49
dwr:如下:
function uploadFile(){
var uploadFile = dwr.util.getValue("uploadFile");
var uploadFileuploadFile_temp = uploadFile.value.replace("\\","/");
var filenames = uploadFile.value.split("/");
var filename = filenames[filenames.length-1];
fileUpload.uploadFile(uploadFile,filename,function(data){
var file_a= document.getElementById("file_a");
file_a.href=data;
file_a.innerHTML=data;
document.getElementById("filediv").style.display="";
});
}

java代码:


public String uploadFile(InputStream uploadFile, String filename)
throws Exception {
System.out.println("ggggggggggg");
return "hello";
WebContext webContext = WebContextFactory.get();
String realtivepath = ((HttpServletRequest) webContext).getContextPath() + "/upload/";
String saveurl = webContext.getHttpServletRequest().getSession()
.getServletContext().getRealPath("/upload");
File file = new File(saveurl + "/" + filename);
// if (!file.exists()) {
// file.mkdirs();
// }
int available = uploadFile.available();
byte[] b = new byte[available];
FileOutputStream foutput = new FileOutputStream(file);
uploadFile.read(b);
foutput.write(b);
foutput.flush();
foutput.close();
uploadFile.close();
return realtivepath + filename;
}

后台报:
这里得到的uploadFile并不是InputStream类型,但是在DWR的代码中直接当InputStream类型使用了,运行的时候会报错:org.directwebremoting.dwrp.BaseCallMarshaller ---Erroring: batchId[2] message[java.lang.IllegalArgumentException: Missing method or missing parameter converters]

ps:dwr用的是2.0,我估计大概是dwr无法识别那个inputstream参数,但是系统用了dwr2.0,好像是改了3.0会好,但是改3.0的话,系统改动很大(只是猜测是不是3.0的问题而已),问一下又没有哪个高手遇到这样的问题啊
...全文
222 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
WarOfTheKing 2012-09-16
  • 打赏
  • 举报
回复
在DWR的代码中直接当InputStream类型使用需要加上如下配置吧:
<convert match="InputStream的完整名" converter="bean"></convert>
oGuHunYeGui123 2012-09-16
  • 打赏
  • 举报
回复
同样问题,但我已经换成3.0了还是报错,不知道什么解决

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧