<link rel="stylesheet" href="uploadify/uploadify.css"type="text/css">
<script src="assets/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="uploadify/swfobject.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.js"></script>
$(document).ready(function(){
$("#mediaID01").uploadify({
'swf' : 'uploadify/uploadify.swf',
'uploader' : '../WxController/saveMediaInServer',//后台处理的请求
'cancelImg' : 'img/uploadify-cancel.png',
'folder' : 'newWxQyServer/img/',//您想将文件保存到的路径
'queueID' : 'fileQueue',//与下面的id对应
'fileDesc' : 'Image Files (*.jpg;*.jpeg;*.gif;*.png)',
'fileExt' : '*.jpg;*.jpeg;*.gif;*.png', //控制可上传文件的扩展名,启用本项时需同时声明fileDesc
'auto' : false,
'multi' : true,
'simUploadLimit' : 2,
'buttonText' : '选择图片',
'buttonImg':'',
'method':'post',
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="mediaID01" />
<p>
<a href="javascript:jQuery('#mediaID01').uploadify('upload','*');">上传</a>
</p>
后台代码:
@RequestMapping(value = "/saveMediaInServer")
@ResponseBody
public List<String> saveMediaInServer(HttpServletResponse response,HttpServletRequest request, @RequestParam(value = "formData", required = false) String formData){
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<String> responseStr= new ArrayList<String>();
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 创建文件夹
Map<String, Object> type = JSON.parseObject(formData, new TypeReference<Map<String, Object>>(){});
Date now=new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String filePath = "/upload/"+type.get("typeName")+"/"+dateFormat.format(now);
String path=request.getSession().getServletContext().getRealPath(filePath);
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 上传文件
MultipartFile mf = entity.getValue();
String filename=String.valueOf(System.currentTimeMillis()) + (int)(Math.random()*1000000);
File uploadFile = new File(path + filename);
try {
FileUtils.copyInputStreamToFile(multipartFile.getInputStream(),file);;
responseStr.add("上传成功");
} catch (IOException e) {
responseStr.add("上传失败");
e.printStackTrace();
}
}
return responseStr;
查看了好多遍代码,不知道哪儿出了问题,之前已经提问过一次,还是没有解决问题。高分跪求大神指导,感激不尽啊~
右键。属性-》生成 改为嵌入的资源试试!
不知道怎么改哎/尴尬
@shayusuf: uploadify/uploadify.swf 找到你的这个文件啊。右键选中 属性-》生成-》改为嵌入的资源试下!这样就能编译到DLL里,好像是这样!试试吧!
@贫民窟大侠: 大侠,能加你的qq么
@贫民窟大侠: 编译之后还是报相同的错误~
@shayusuf: 你编译之后传了这个dll了吗?
@贫民窟大侠: 谷歌F12。network,查看上传文件时候的请求。看请求的信息!你这是编译错误还是运行时错误?
@贫民窟大侠: 传了,运行时错误吧~
@shayusuf: 刚查了一下,org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest 是这个问题,需要在xml文件中添加配置 请问应该怎么添加
看看你的服务器配置,是否兼容。。。
HTTP Status 500 - Request processing failed; nested exception is java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
type Exception report
message Request processing failed; nested exception is java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest com.szinfo.controllers.WxController.saveMediaInServer(WxController.java:286) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:497) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
服务器配置没问题~
@shayusuf: 嵌套异常,捕获不到你添加的资源 'uploadify/uploadify.swf',下面有人说了。。
这样做就应该好了
@搁忆: 还是报相同的错误~
500, 把后台报错的内容贴上来
type Exception report
message Request processing failed; nested exception is java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest com.szinfo.controllers.WxController.saveMediaInServer(WxController.java:286) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:497) org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
@shayusuf: 文件上传时候那个multirpart..转换错误不知道是那个flash提交时候参数有问题还是spring配置的事
@之奇一昂: 如果是flash提交时候参数的问题,应该怎么解决呢
@shayusuf: 不懂flash啊。。爱莫能助……
@之奇一昂: 刚查了一下,org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest 是这个问题,需要在xml文件中添加配置 请问应该怎么添加
@shayusuf:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="104857600"/> <property name="maxInMemorySize" value="4096"/> </bean>