java.lang.ClassCastException: org.apache.shiro.web.servlet.ShiroHttpServletRequest cannot be cast to

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

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

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

如下:

<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>



@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);
		}
	}



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值