支持中文的jsp文件上传组件:jspSmartUpload.jar下载
jar包的存放位置:WEB-INF\lib下。
upload_image.html
<form method="post" action="new_upload.jsp" enctype="multipart/form-data"> <input type="file" name="file"> <input type="submit" name="Submit" value="上传"> </form>
image_upload.jsp
<%@ page contentType="text/html; charset=gb2312" import="com.jspsmart.upload.SmartUpload" %> <html> <head> <title>文件上传处理页面</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <% SmartUpload su = new SmartUpload(); su.initialize(pageContext); try{ // 设定允许上传的文件(通过扩展名限制) su.setAllowedFilesList("jpg,png,gif,bmp"); su.upload(); su.save("/upload"); } catch (Exception e){ %> <SCRIPT language=javascript> alert("只允许上传.jpg/.gif/.png/.bmp类型图片文件"); window.location='upload_image.html'; </script> <% }try{ com.jspsmart.upload.File file = su.getFiles().getFile(0); if (file.isMissing()){%> <SCRIPT language=javascript> alert("请先选择要上传的文件"); window.location='upload_image.html'; </script> <%} else{ // 显示当前文件信息 out.println("你上传的图片是:<img src='upload/"+file.getFileName()+"' >"); } }catch (Exception e){ out.print(e.toString()); } %> </body> </html>
相关文章:
基于jspSmartUpload的Jsp文件上传:防止文件重名被覆盖的解决方法
基于jspSmartUpload的Jsp文件上传实例
125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/2921.html