日期:2014-05-19  浏览次数:20788 次

dwr 上传文件 出错 求高手解决下谢谢(急)
错误提示 
2012-8-2 15:07:53 org.directwebremoting.util.CommonsLoggingOutput warn
警告: Marshalling exception: Missing method or missing parameter converters
2012-8-2 15:07:53 org.directwebremoting.util.CommonsLoggingOutput warn
警告: --Erroring: batchId[0] message[java.lang.IllegalArgumentException: Missing method or missing parameter converters]


后台代码
Java code

public class Dwr {
    public String upload(InputStream is,String filename) throws IOException {
        //WebContext可以获取HttpServlet的对象
        WebContext wc = WebContextFactory.get();
        HttpServletRequest req = wc.getHttpServletRequest();
        String realpath = req.getSession().getServletContext().getRealPath("upload");
        String fn = FilenameUtils.getName(filename);
        String filepath = realpath+"/"+fn;
    //    FileUtils.copyInputStreamToFile(is, new File(filepath));
        return filepath;
    }
}


前台代码
Java code


<script type="text/javascript" src='<%=request.getContextPath()%>/dwr/engine.js '></script>
<script type="text/javascript" src='<%=request.getContextPath()%>/dwr/util.js '></script>
<script type="text/javascript" src='<%=request.getContextPath()%>/dwr/interface/myDwr.js'></script>
<script type="text/javascript">
function upload() {
    var file = dwr.util.getValue("myfile");
    alert(dwr.util.getValue("myfile").value);
    alert(file);
    myDwr.upload(file,file.value,function(data){
        alert(data);
    });
}
</script>
</head>
<body>
    <input type="file" id="myfile"/>    
    <input type="button" value="上传文件" onclick="upload()"/>
</body>



dwr.xml配置
Java code


    <create creator="new" javascript="myDwr">
    <param name="class" value="dwrTest.Dwr" />
         <convert converter="bean" match="java.lang.StackTraceElement" />





------解决方案--------------------
我的DWR上传是这样写的
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html> 
<head>
<script type="text/javascript">
function suffixalWord(){
var len = document.getElementById("file").value.length;
if(document.getElementById("file").value.substring(len-3,len) != "doc"){
document.getElementById("form").reset();
alert("上传的文档不是Word,请重新选择");
}else document.getElementById("form").submit();
}

</script>


</head>
<body>
<center>
<h1>请选择word文档</h1>
<form action="uploadWord.jsp" method="post" enctype="multipart/form-data" id="form">
<p>上传文件:<input type="file" name="file" id="file">
<p><input type="button" value="提交" onclick="suffixalWord()"/><input type="reset" value="重置"/></p>
</fo