0 0

dwr文件上传不成功,帮忙看看啊。线等。。0

MyDwrService
	/**
	 * 上传文件
	 * @throws IOException 
	 */
	public String upload(InputStream is,String filename) throws IOException{
		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));
		System.out.println(fn);
		return filepath;
	}

dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd">
<dwr>
  <allow>
    <create creator="new">
      <param name="class" value="org.tony.dwr.service.MyDwrService"/>
    </create>
    <convert converter="bean" match="org.tony.dwr.model.User"/>
    <convert converter="bean" match="org.tony.dwr.model.Group"/>
    <convert converter="exception" match="java.lang.Exception">
    </convert>
    <convert converter="bean" match="java.lang.StackTraceElement"/> 
  </allow>
  <allow>
  	<create creator="new" javascript="SendMsg">
  		<param name="class">org.tony.dwr.message.SendMsg</param>
  	</create>
  </allow>
</dwr>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="dwr">
	<listener>
		 <listener-class>
		    org.directwebremoting.servlet.EfficientShutdownServletContextAttributeListener
		 </listener-class>
	</listener>
	<listener>
		 <listener-class>
		    org.directwebremoting.servlet.EfficientShutdownServletContextListener
		 </listener-class>
	</listener>
  <servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>
 
</web-app>

dwr05.jsp
<%@  page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
	<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/MyDwrService.js"></script>
	<script type="text/javascript">
		function fileUpload(){
			var file=dwr.util.getValue("uploadfile");
			alert(file);
			alert(file.value);
			MyDwrService.upload(file,file.value,function(data){
				alert(data);
			});
		}
	</script>
</head>
<body>
	<input type="file" id="uploadfile"/>
	<input type="button" value="上传文件" onclick="fileUpload()">
</body>
</html>


为什么文件上传不成功,在页面端都有值 为什么走不到后台代码没有
2013年9月08日 20:39
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics