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. ...
随机推荐
- android volley get请求使用
调用百度api微博热门精选接口,使用了volley,简单说说volley get的请求方式的使用 header的设置和请求参数的设置,见代码如下: private void getWeixinNews ...
- no.4 抽奖测试
#-*-coding=gbk-*- import sys import random a=[] try: for x in range(1,20+1,1): #打印20人数编号 a.append(x) ...
- sqlalchemy 的 raw sql 方式使用示例
#获取数据库 from sqlalchemy import create_engine db = create_engine("sqlite:///:memory:", echo= ...
- 用python简单处理图片(1):打开\显示\保存图像
一提到数字图像处理,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因此, ...
- Android Drawable的9种子类 介绍
原文: Android Drawable的9种子类 介绍 Drawable 在android里面 就是代表着图像,注意是图像 而不是图片. 图片是图像的子集.图像除了可以包含图片以外 还可以包含颜 ...
- 炫酷JQUERY自定义对话框插件JDIALOG_JDIALOG弹出对话框和确认对话框插件
多种类型自定义对话框插件jDialog是一款基于jquery实现的轻量级多种类型的自定义对话框插件 在项目开发中.一般会美化 alert(); 的样式.那么今天我就和大家分享一款非常炫的插件 先来看一 ...
- IM架构(一)JSQMessagesViewController
JSQMessagesViewController 是 Jesse Squires 开发的一个消息界面的 UI 库.
- CUDA编程学习(三)
我们知道一个grid包含多个block,而一个block又包含多个thread,下面将是如何进行下thread中的并行. /**** Splot a block into parallel threa ...
- HoloToolkit项目源码剖析 - Spatial Mapping功能实现
就像我之前所描述的,HoloToolkit项目是微软基于Unity内置的底层API封装的一套工具集合,帮助我们快速使用Unity集成开发HoloLens应用. 本文主要通过源码研究其中Spatial ...
- 免费的SSL证书,免费为微信小程序搭建https
StartSSL 也免费提供了一个证书(纯英文) 申请地址:https://www.startssl.com/Account?r=L1ZhbGlkYXRl 阿里云免费提供的证书 https://com ...