MyEclipse------如何添加jspsmartupload.jar+文件上传到服务器
下载地址: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
<!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>
方法二:通过跳转Servlet上传
public class upfile extends HttpServlet {
private static final long serialVersionUID = 1L; public upfile() {
super();
} public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312"); SmartUpload up=new SmartUpload(); try{
/*
第一个参数是传递一个Servlet,在servlet中传递this就可以了;
第二个和第三个参数是request与response不多说明了;
第四个参数是发生错误后的url路径地址,如果没有可以键入null;
第五个参数是是否需要session,这里可以写入true;
第六个参数是缓存大小,我们用了8*1024;
第七个蚕食是是否需要刷新,键入ture;*/
PageContext context = JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true, 8*1024, true);
up.initialize(context);
up.setTotalMaxFileSize(5*1024*1024); //上传的总文件大小不能超过这个
up.upload(); //获取文件名
//String fn=up.getFiles().getFile(0).getFieldName(); String path="E:\\Tomcat\\webapps\\MyWeb\\myfile";
//java.io.File d=new java.io.File(path);
File d=new File(path);
if(!d.exists()){
d.mkdirs();
}
up.save(path);
//System.out.print(fn);
//System.out.print("文件上传成功啦!!!");
RequestDispatcher dispatcher=request.getRequestDispatcher("/splitpage2/downfile.jsp");
dispatcher.forward(request, response); //无法传参
//response.sendRedirect("http://localhost:8080/MyWeb/splitpage2/list.jsp");
}
catch(Exception e){
e.printStackTrace();
} } public void init() throws ServletException {
// Put your code here
} }
MyEclipse------如何添加jspsmartupload.jar+文件上传到服务器的更多相关文章
- maven jar包上传到服务器
maven jar包上传到服务器时出现pom文件没有上传上去,致使该jar包再被使用的时候没有依赖,jar包调用出错 解决办法,将pom文件一起deploy上去 mvn deploy:deploy-f ...
- Java实现文件上传到服务器(FTP方式)
Java实现文件上传到服务器(FTP方式) 1,jar包:commons-net-3.3.jar 2,实现代码: //FTP传输到数据库服务器 private boolean uploadServer ...
- Linux 文件上传Linux服务器
进入命令行 在图形化桌面出现之前,与Unix系统进行交互的唯一方式就是借助由shell所提供的文本命令行界面(command line interface,CLI).CLI只能接受文本输入,也只能显示 ...
- 基于paramiko将文件上传到服务器上
通过安装使用paramiko模块,将本地文件上传到服务器上 import paramiko import datetime import os hostname = '服务器ip' username ...
- ubuntu中将本地文件上传到服务器
(1)在本地的终端下,而不是在服务器上.在本地的终端上才能将本地的文件拷入服务器. (2) scp -r localfile.txt username@192.168.0.1:/home/userna ...
- 一、手把手教你docker搭建fastDFS文件上传下载服务器
在搭建fastDFS文件上传下载服务器之前,你需要准备的有一个可连接的linux服务器,并且该linux服务器上已经安装了docker,若还有没安装docker的,先百度自行安装docker. 1.执 ...
- 移动商城第四篇【Controller配置、添加品牌之文件上传和数据校验】
Controller层配置 编写SpringMVC的配置文件 springmvc.xml <?xml version="1.0" encoding="UTF-8&q ...
- JSP多文件上传到服务器
问题描述: 作为一个Java开发Web方向的程序员,很重要的一个功能,就是上传文件功能是一定要掌握的,今天整理了一下代码. 1.JSP显示界面代码和动态添加上传文件个数. <%@ page la ...
- 微信录音文件上传到服务器以及amr转化成MP3格式
微信公众号音频接口开发 根据业务需求,我们可能需要将微信录音保存到服务器,而通过微信上传语音接口上传到微信服务器的语音文件的有效期只有3天,所以需要将文件下载到我们自己的服务器. 上传语音接口 wx. ...
随机推荐
- 22Mybatis_订单商品数据模型_多对多查询以及对多对多查询的总结
之前讲了一对一,一对多查询,这篇文章讲的是多对多. 先给出需求:查询用户及用户购买商品信息. 我们由之前的文章知道,这个需求是多对多的. 还是那个终止我们的mybatis所做的不管是之前的一对一还是一 ...
- html的解析
Web页面运行在各种各样的浏览器当中,浏览器载入.渲染页面的速度直接影响着用户体验 简单地说,页面渲染就是浏览器将html代码根据CSS定义的规则显示在浏览器窗口中的这个过程.先来大致了解一下浏览器都 ...
- [转]Hive/Beeline 使用笔记
FROM : http://www.7mdm.com/1407.html Hive: 利用squirrel-sql 连接hive add driver -> name&example u ...
- Wireshark命令行工具tshark
Wireshark命令行工具tshark 1.目的 写这篇博客的目的主要是为了方便查阅,使用wireshark可以分析数据包,可以通过编辑过滤表达式来达到对数据的分析:但我的需求是,怎么样把Data部 ...
- java String.getBytes()编码问题——String.getBytes(charset)
String的getBytes()方法是得到一个字串的字节数组,这是众所周知的.但特别要注意的是,本方法将返回该操作系统默认的编码格式的字节数组.如果你在使用这个方法时不考虑到这一点,你会发现在一个平 ...
- C/C++关于string.h头文件和string类
学习C语言时,用字符串的函数例如stpcpy().strcat().strcmp()等,要包含头文件string.h 学习C++后,C++有字符串的标准类string,string类也有很多方法,用s ...
- 20135316王剑桥 linux第十周课实验笔记
关于who 功能说明:显示目前登入系统的用户信息. 语 法:who [-Himqsw][--help][--version][am i][记录文件] 补充说明:执行这项指令可得知目前有那些用户登入系统 ...
- 安装mysql(zip格式安装包)
mysql下载地址:http://www.mysql.com/ 一. zip格式,解压缩之后要进行配置.解压之后可以将该文件夹改名,放到合适的位置,比如把文件夹改名为MySQL Server 5.6( ...
- Google Map API key 获取方法
要想使用google map api 必须从google网站上获取key之后才有权限使用,但是要想申请key必须要有证明书,也就是所谓的MD5.下面一步一步来说明: 步骤1: 如果你使用的是eclip ...
- php图片水印添加,压缩,剪切的封装类
php对图片文件的操作主要是利用GD库扩展.当我们频繁利用php对图片进行操作时,会自然封装很多函数,否则会写太多重复的代码.当有很多对图片的相关函数的时候,我们可以考虑将这些函数也整理一下,因而就有 ...