我是靠谱客的博主 舒服手机,这篇文章主要介绍java.lang.ClassCastException: org.apache.shiro.web.servlet.ShiroHttpServletRequest cannot be cast to,现在分享给大家,希望可以做个参考。

今天在做上传的时候,遇到一个这亲的问题。如题目。

以为是配置文件这与错了。结果查看了好长时间,没找一以错。程序里也没有问题。

最后,问题出在了jquery validate 验证这里。只好改成在form里提交。

如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<form id="importYuanLiaoFileForm" name="importYuanLiaoFileForm" action="${ctx}/xxxxx/getUpLoadFile.do" method="post" enctype ="multipart/form-data" target="hidden_frame"> <div class="ui-widget"> <div id="importYuanLiaoFile_toolbar" class="ui-widget-header ui-state-default"> <button id="importYuanLiaoFileSaveBtn" type="button">确定</button> <button id="importYuanLiaoFileCloseBtn" type="button">关闭</button> </div> <div id="importYuanLiaoFileErrorMsg" class="errorCls"></div> <fieldset> <legend>导入</legend> <table cellspacing="5" cellpadding="5" border="0"> <tr> <td>添加Excel文件</td> <td> <input type="file" id="importFile" name="importFile"/><font color="red">*</font> </td> </tr> </table> </fieldset> </div> </form> <iframe name='hidden_frame' id="hidden_frame" style="display:none"></iframe>



复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@RequestMapping("getUpLoadFile") @SuppressWarnings({"unchecked","rawtypes"}) public void getUpLoadFile(HttpServletRequest request, HttpServletResponse response) throws IOException{ MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); String ctxPath=request.getSession().getServletContext().getRealPath("/")+"fileUpload"; //文件上传存储路径 ctxPath += File.separator; // 创建文件夹 File file = new File(ctxPath); if (!file.exists()) { file.mkdirs(); } String fileName = null; String newName = null; for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { // 上传文件 MultipartFile mf = entity.getValue(); fileName = mf.getOriginalFilename();//获取原文件名 //获得当前时间的最小精度 SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS"); newName = format.format(new Date()); //获得三位随机数 Random random = new Random(); for(int i = 0; i < 3; i++){ newName = newName + random.nextInt(9); } File uploadFile = new File(ctxPath + newName+fileName.substring(fileName.lastIndexOf("."))); try { FileCopyUtils.copy(mf.getBytes(), uploadFile); } catch (IOException e){ e.printStackTrace(); } } response.setHeader("Content-type", "text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); // response.getWriter().write(newName+fileName.substring(fileName.lastIndexOf("."))); //处理上传数据 try { String importFile = ctxPath + newName+fileName.substring(fileName.lastIndexOf(".")); importFile = importFile.replaceAll("\\","/"); response.getWriter().write("<script>parent.upLoadFinsh();</script>"); //这里设置是返回时的处理方法。直接在js写function upLoadFinsh(){}就行 } catch (Exception e) { logger.error("保存失败", e); } }



最后

以上就是舒服手机最近收集整理的关于java.lang.ClassCastException: org.apache.shiro.web.servlet.ShiroHttpServletRequest cannot be cast to的全部内容,更多相关java.lang.ClassCastException:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部