基于jspSmartUpload的Jsp文件上传实例(只能上传图片格式文件)

支持中文的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

(0)
江山如画的头像江山如画管理团队
基于jspSmartUpload的Jsp文件上传:防止文件重名被覆盖的解决方法
上一篇 2018年12月11日 下午3:05
基于jspSmartUpload的JSP文件上传(一次可以上传多个文件)
下一篇 2018年12月11日 下午3:23

99%的人还看了以下文章

  • python 中time.gmtime()与localtime()的区别

    gmtime转换的时间是UTL时间,与北京时间相差了8个小时 import time print(time.time()) print(time.strftime(“%Y-%m-%d 星期%w %H:%M:%S”,time.localtime())) print(time.strftime(“%Y-%m-%d 星期%w %H:%M:%S”,time.gmti…

    2022年7月15日
    10.0K0
  • 10秒倒计时、考试结束倒计时功能实现代码-JS

    注册成功或登录后网页会有倒计时,如5秒后跳转到哪个页面的功能。 在做一些在线测试,网上考试系统时,会用到倒计时功能。 如网上考试系统里,会有时间提示离考试结束还有多长时间,临近考试结束剩10分钟,还可以弹窗提示考生。 JavaScript实现倒计时功能代码 <!DOCTYPE html> <html> <head> &lt…

    2020年11月1日
    4.9K0
  • 第4课:标识符和关键字

     1.标识符 在程序中使用的变量名、函数名、标号等统称为标识符。除库函数的函数名由系统定义外,其余都由用户自定义。C 规定,标识符只能是字母(A~Z,a~z)、数字(0~9)、下划线(_)组成的字符串,并且其第一个字符必须是字母或下划线。 以下标识符是合法的:        a, x,  x3, BOOK_1, sum5 以下标识符是非法的:     3a …

    2020年4月5日
    8.3K0
  • Python编程入门:英文词频统计

    text = “Got tho on super sale. Love it! Cuts my drying time in half Reckon I have had this about a year now,\ at least 7 months. Works great, I use it 5 days a week, blows hot air,…

    2023年10月3日
    12.2K0
  • JSP+MySQL MVC综合案例:完整的分页查询

    JSP+MySQL数据库开发教程,MVC综合案例,完整的分页查询代码。

    2018年2月22日
    8.0K0
  • Windows10+IIS+PHP7+MySQL5.7环境搭建

    Windows10+IIS+PHP7+MySQL5.7环境搭建Windows10+IIS+PHP7+MySQL5.7环境搭建Windows10+IIS+PHP7+MySQL5.7环境搭建Windows10+IIS+PHP7+MySQL5.7环境搭建

    IIS配置 本次搭建使用的系统是Windows7,Windows8,10与此类似。 开启IIS 开始–>控制面板–>程序和功能,点击左边栏的开启或关闭Windows功能,如图: 选择Internet信息服务并选择里面的CGI。打开浏览器,输入localhost或127.0.0.1,可以正常打开网页则说明开启成功。 新建站点…

    2021年8月14日 编程开发
    9.3K0

发表回复

登录后才能评论