MyEclipse------如何添加jspsmartupload.jar+文件上传到服务器
2016-03-24 17:31
591 查看
下载地址:http://download.csdn.net/detail/heidan2006/182263
如何添加jspsmartupload.jar:
右键“Web”工程-》properties-》Libraries-》Add External JARs...-》找到“jspsmartupload.jar”,添加进去
-》点击“OK”-》找到“E:\MyEclipse2014\projects\Web\WebRoot\WEB-INF\lib”路径,把“jspsmartupload.jar”添加进去
-》重启tomcat,不然出现invalid
uploadForm.html
usingsmartupload.jsp
如何添加jspsmartupload.jar:
右键“Web”工程-》properties-》Libraries-》Add External JARs...-》找到“jspsmartupload.jar”,添加进去
-》点击“OK”-》找到“E:\MyEclipse2014\projects\Web\WebRoot\WEB-INF\lib”路径,把“jspsmartupload.jar”添加进去
-》重启tomcat,不然出现invalid
uploadForm.html
<!DOCTYPE html> <html> <head> <title>uploadForm.html</title> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=gbk"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> <form action="usingsmartupload.jsp" method="post" enctype="multipart/form-data" name="theFile"> <input type="file" name="file" size="30"/><br> <input type="submit" value="上传" name="btn"> </form> </body> </html>
usingsmartupload.jsp
<%@page import="java.io.File"%> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!-- java.sql.*包可以不导 --> <%@page import="java.sql.*" %> <%@page import="com.jspsmart.upload.*" %> <%@page import="java.io.*" %> <jsp:useBean id="the" scope="page" class="com.jspsmart.upload.SmartUpload"/> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'usingsmartupload.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- 这段代码可以不加 --> <meta http-equiv="Content-Type" content="text/html;charset=gb2312"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% try{ the.initialize(pageContext); the.setTotalMaxFileSize(5*1024*1024); the.upload(); String fn=the.getFiles().getFile(0).getFieldName(); path=request.getRealPath("")+"\\myfile"; //java.io.File d=new java.io.File(path); File d=new File(path); if(!d.exists()){ d.mkdirs(); } the.save(path); //the.save("E:\\FFOutput\\"); out.print(fn); out.print("文件已上传成功!!!"); } catch(Exception e){ e.printStackTrace(); } %> </body> </html>
相关文章推荐
- java图片处理——多张图片合成一张Gif图片并播放或Gif拆分成多张图片
- android使用andFix增量更新,在ubuntu系统下,Eclipse版本
- MySQL------如何安装mysql-connector-java-5.1.38.zip
- 礼拜四log~java函数replaceAll报错解决方案 & 一些常用jq方法 & java函数addAll
- JAVA中的反射机制
- 使用Eclipse构建Maven项目 (step-by-step)
- 聊聊并发-Java中的Copy-On-Write容器
- 监控Java的GC状态
- Eclipse项目导入AS(Android Studio)
- 深入研究java.lang.ThreadLocal类
- 聊聊并发(七)——Java中的阻塞队列
- Spring定时任务的几种实现
- hdu2035java
- java websocket
- SpringMVC学习系列-后记 解决GET请求时中文乱码的问题
- JDK源码中使用的设计模式
- 创建基于注解的springmvc的流程
- 聊聊并发(三)Java线程池的分析和使用
- java后台接受json数组中嵌套json数组的处理
- java如何将int类型的值转化成String类型的值?