首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

DWR下传文件 提示File uploads not supported?求大神

2012-09-17 
DWR上传文件 提示File uploads not supported?求大神dwr配置create javascriptUploadFile creatorne

DWR上传文件 提示File uploads not supported?求大神
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包自己去下。网上都有的。

热点排行