dwr配置
<create javascript="UploadFile" creator="new">
<param name="class" value="com.tt.dwrupload.UploadFile"></param>
<include method="upload"/>
</create>
web.xml配置
<servlet>
<servlet-name>DWRServlet</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>DWRServlet</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
UploadFile 类代码 仅仅是进行测试。看看能否正常返回,结果不行。
public class UploadFile {
public int upload(FileTransfer fileTransfer) {
return 10;
}
}
js代码:
function upload() {
var uploadFile=document.getElementById("uploadFile");
UploadFile.upload(uploadFile,function(result){
alert(result);
});
}
页面代码:
<script type='text/javascript' src='/DWRFileUpload/dwr/engine.js'></script>
<script type='text/javascript' src='/DWRFileUpload/dwr/interface/UploadFile.js'></script>
<script type='text/javascript' src='/DWRFileUpload/dwr/util.js'></script>
<script type="text/javascript" src="upload.js"></script>
</head>
<body>
This is my JSP page. <br>
<input type="file" id="uploadFile"/>
<input type="button" value="xxx" onclick="upload()"/>
</body>
jar包:
commons-logging-1.1.1.jar
dwr.jar (3.0)
------解决方案--------------------
帮你看了一哈,自己也写了一个demo,发现没有什么错,因为你少添加了Jar包,加入这两个jar包即可。commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
如果没有这两个jar包自己去下。网上都有的。