首页 新闻 会员 周边 捐助

在spring mvc框架下,用uploadify插件上传文件,总是不成功,报500(internal server error)错误

0
悬赏园豆:100 [已解决问题] 解决于 2015-12-10 16:47

<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的主页 shayusuf | 初学一级 | 园豆:31
提问于:2015-11-30 14:27
< >
分享
最佳答案
0

右键。属性-》生成 改为嵌入的资源试试!

收获园豆:50
大楚打码人 | 老鸟四级 |园豆:4313 | 2015-11-30 15:43

不知道怎么改哎/尴尬

shayusuf | 园豆:31 (初学一级) | 2015-11-30 15:54

@shayusuf: uploadify/uploadify.swf 找到你的这个文件啊。右键选中  属性-》生成-》改为嵌入的资源试下!这样就能编译到DLL里,好像是这样!试试吧!

大楚打码人 | 园豆:4313 (老鸟四级) | 2015-11-30 16:13

@贫民窟大侠: 大侠,能加你的qq么

shayusuf | 园豆:31 (初学一级) | 2015-11-30 16:36

@贫民窟大侠: 编译之后还是报相同的错误~

shayusuf | 园豆:31 (初学一级) | 2015-11-30 17:08

@shayusuf: 你编译之后传了这个dll了吗?

大楚打码人 | 园豆:4313 (老鸟四级) | 2015-11-30 17:34

@贫民窟大侠: 谷歌F12。network,查看上传文件时候的请求。看请求的信息!你这是编译错误还是运行时错误?

大楚打码人 | 园豆:4313 (老鸟四级) | 2015-11-30 17:35

@贫民窟大侠: 传了,运行时错误吧~

shayusuf | 园豆:31 (初学一级) | 2015-12-01 09:16

@shayusuf: 刚查了一下,org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest 是这个问题,需要在xml文件中添加配置  请问应该怎么添加

shayusuf | 园豆:31 (初学一级) | 2015-12-01 09:56
其他回答(2)
0

看看你的服务器配置,是否兼容。。。

收获园豆:20
搁忆 | 园豆:612 (小虾三级) | 2015-11-30 15:06

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)

支持(0) 反对(0) shayusuf | 园豆:31 (初学一级) | 2015-11-30 15:36

服务器配置没问题~

支持(0) 反对(0) shayusuf | 园豆:31 (初学一级) | 2015-11-30 15:37

@shayusuf: 嵌套异常,捕获不到你添加的资源  'uploadify/uploadify.swf',下面有人说了。。

这样做就应该好了

支持(0) 反对(0) 搁忆 | 园豆:612 (小虾三级) | 2015-11-30 16:33

@搁忆: 还是报相同的错误~

支持(0) 反对(0) shayusuf | 园豆:31 (初学一级) | 2015-11-30 17:08
0

500, 把后台报错的内容贴上来

收获园豆:30
之奇一昂 | 园豆:1421 (小虾三级) | 2015-11-30 15:19

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)
支持(0) 反对(0) shayusuf | 园豆:31 (初学一级) | 2015-11-30 15:35

@shayusuf: 文件上传时候那个multirpart..转换错误不知道是那个flash提交时候参数有问题还是spring配置的事

支持(0) 反对(0) 之奇一昂 | 园豆:1421 (小虾三级) | 2015-11-30 19:57

@之奇一昂: 如果是flash提交时候参数的问题,应该怎么解决呢

支持(0) 反对(0) shayusuf | 园豆:31 (初学一级) | 2015-12-01 09:17

@shayusuf: 不懂flash啊。。爱莫能助……

支持(0) 反对(0) 之奇一昂 | 园豆:1421 (小虾三级) | 2015-12-01 09:37

@之奇一昂: 刚查了一下,org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest 是这个问题,需要在xml文件中添加配置  请问应该怎么添加

支持(0) 反对(0) shayusuf | 园豆:31 (初学一级) | 2015-12-01 09:56

@shayusuf: 

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
      <property name="maxUploadSize" value="104857600"/>  
      <property name="maxInMemorySize" value="4096"/>  
</bean> 
支持(0) 反对(0) 之奇一昂 | 园豆:1421 (小虾三级) | 2015-12-01 12:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册