使用jspsmartupload上传文件抛出的java.lang.IllegalStateException异常
2016-10-11 22:29
711 查看
在使用jspsmartupload组件上传文件时,如果同时上传多个文件就会抛出该异常,在此做下记录
<fieldset> <legend align="left">文件上传</legend> <p>作者:<input type="text" id="author" name="author" /></p> <p>出版社:<input type="text" id="press" name="press" /></p> <p>上传文件:<input type="file" name="filename" /></p> <p>上传文件:<input type="file" name="filename" /></p> <!-- 此处使用多文件上传会抛出异常java.lang.IllegalStateException: Cannot forward after response has been committed --> <P><input type="submit" value="点击上传" /></P> <!-- <input type="hidden" name="flag" value="upload" /> --> </fieldset>
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //实例化JspSmartUpload组件中的SmartUpload对象 该类对象的作用是实现上传 SmartUpload smartUpload = new SmartUpload(); //对 smartUpload对象进行初始化 smartUpload.initialize(this.getServletConfig(), request, response); try { //调用upload方法实现文件 该方法会抛出异常 smartUpload.upload(); Request req = smartUpload.getRequest(); String author = req.getParameter("author"); String press = req.getParameter("press"); System.out.println("author="+author); Files files = smartUpload.getFiles(); for(int i=0;i<files.getCount();i++){ // 返回 JspSmartUpload 组件中的File类,每一个file对象代表一条form表单的文件域 File file = files.getFile(i); //获取上传文件的文件名 String fileName = file.getFileName(); //将上传的文件保存到指定的位置下 file.saveAs(SAVEPATH+fileName); //向request作用域中存入信息 request.setAttribute("author", author); request.setAttribute("press", press); request.setAttribute("msg", "文件上传成功!"); request.setAttribute("savepath", SAVEPATH); request.getRequestDispatcher("success.jsp").forward(request, response); } } catch (SmartUploadException e) { e.printStackTrace(); } }
异常提示:java.lang.IllegalStateException: Cannot forward after response has been committed
相关文章推荐
- Servlet.service() for servlet jsp threw exception java.lang.Il在jsp中使用jspsmartupload组件下载文件时将抛出异常的解决方案
- [JAVA]彻底抛弃 jspSmartUpload,使用 common-fileupload 实现文件上传
- Java【代码】使用jspSmartUpload实现文件上传demo
- 关于使用jspsmartupload.jar进行文件的上传与下载
- 【Jsp】使用jspsmartupload完成简单的文件上传系统
- 【Jsp】使用AjaxFileUploader与jspsmartupload完成不刷新的Ajax文件上传系统
- java使用smartupload组件实现文件上传的方法
- java使用smartupload组件实现文件上传的方法
- 使用jspSmartUpload实现文件的上传
- 在jsp中使用smartupload组件上传文件
- 在jsp中使用smartupload组件上传文件- -
- 在jsp中使用smartupload组件上传文件
- 项目开发技巧(四):使用JspSmartupload实现文件上传下载(一):JspSmart之upload组件源码及使用
- 项目开发技巧(四):使用JspSmartupload实现文件上传下载(二):jspSmartUpload上传下载全攻略(ZZ)
- 项目开发技巧(四):使用JspSmartupload实现文件上传下载(三):jspsmartupload samples
- 在jsp中使用smartupload组件上传文件
- 使用JspSmartUpload组件上传文件
- Struts action 中使用jspsmartupload 上传文件
- 使用jspsmartupload解决enctype引起的无法同时上传文件和接值的问题
- 在jsp中使用smartupload组件上传文件