下载地址: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+文件上传到服务器的更多相关文章

  1. maven jar包上传到服务器

    maven jar包上传到服务器时出现pom文件没有上传上去,致使该jar包再被使用的时候没有依赖,jar包调用出错 解决办法,将pom文件一起deploy上去 mvn deploy:deploy-f ...

  2. Java实现文件上传到服务器(FTP方式)

    Java实现文件上传到服务器(FTP方式) 1,jar包:commons-net-3.3.jar 2,实现代码: //FTP传输到数据库服务器 private boolean uploadServer ...

  3. Linux 文件上传Linux服务器

    进入命令行 在图形化桌面出现之前,与Unix系统进行交互的唯一方式就是借助由shell所提供的文本命令行界面(command line interface,CLI).CLI只能接受文本输入,也只能显示 ...

  4. 基于paramiko将文件上传到服务器上

    通过安装使用paramiko模块,将本地文件上传到服务器上 import paramiko import datetime import os hostname = '服务器ip' username ...

  5. ubuntu中将本地文件上传到服务器

    (1)在本地的终端下,而不是在服务器上.在本地的终端上才能将本地的文件拷入服务器. (2) scp -r localfile.txt username@192.168.0.1:/home/userna ...

  6. 一、手把手教你docker搭建fastDFS文件上传下载服务器

    在搭建fastDFS文件上传下载服务器之前,你需要准备的有一个可连接的linux服务器,并且该linux服务器上已经安装了docker,若还有没安装docker的,先百度自行安装docker. 1.执 ...

  7. 移动商城第四篇【Controller配置、添加品牌之文件上传和数据校验】

    Controller层配置 编写SpringMVC的配置文件 springmvc.xml <?xml version="1.0" encoding="UTF-8&q ...

  8. JSP多文件上传到服务器

    问题描述: 作为一个Java开发Web方向的程序员,很重要的一个功能,就是上传文件功能是一定要掌握的,今天整理了一下代码. 1.JSP显示界面代码和动态添加上传文件个数. <%@ page la ...

  9. 微信录音文件上传到服务器以及amr转化成MP3格式

    微信公众号音频接口开发 根据业务需求,我们可能需要将微信录音保存到服务器,而通过微信上传语音接口上传到微信服务器的语音文件的有效期只有3天,所以需要将文件下载到我们自己的服务器. 上传语音接口 wx. ...

随机推荐

  1. C语言 文件操作8--fputs()和fgets()

    //fputs()和fgets() #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> # ...

  2. Returns: range-based (not absolute) index within the current range

    /** * This method is for use with UI Table addRows buttons that require the * addition of multiple r ...

  3. MySql系列:中文写入数据库出现错误java.sql.SQLException: Incorrect string value: '\xE5\xxxx' for column 'xxxx' at row 1及其解决方法

    在将kft-activiti-demo的数据库连接改为mysql之后,可以正常登陆,但是在新建请假流程的时候出现如下错误:   Caused by: java.sql.SQLException: In ...

  4. 从0开始学Java——JSP&Servlet——如何在Eclipse中配置Web容器为tomcat

    windows- >Preferences -> Server->runtime Envirement ->Add 点击下一步,然后按照如下设置:  

  5. iOS开发的设计模式

    ios开发学习中,经常弄不清楚ios的开发模式,今天我们就来进行简单的总结和探讨~ (一)代理模式 应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现. 优势:解耦合 敏捷 ...

  6. Javascript的字面量对象以及如何拆解字面量对象

    简单的说,字面量对象提供了一直非常方便构建新对象的方式,它的格式非常简单且容易阅读.是大多数前端程序员在构建对象时比较推崇的一种方式. 格式: var person = { name : " ...

  7. Node基础:域名解析DNS(ok)

    写在前面 Nodejs学习手册,基础总结之DNS模块.对从事web开发的同学来说,DNS解析再熟悉不过,在nodejs中也有一个模块可以完成dns解析的工作,使用非常简单.直接进入主题. 域名解析:d ...

  8. 第四章 一切从IL开始

    从这一部分开始,就开始讲.net的本质了,这第四章就是讲有关IL(中间语言)的内容,主要利用工具,看看VS到底编译出来的是什么东西,从中我们可以看到实现的方式和过程.有助于我们更好的了解.net的本质 ...

  9. Bootstrap系列 -- 35. 按钮的向下向上三角形

    按钮的向下三角形,我们是通过在<button>标签中添加一个“<span>”标签元素,并且命名为“caret”. <div class="btn-group d ...

  10. [USACO2002][poj1947]Rebuilding Roads(树形dp)

    Rebuilding RoadsTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 8589 Accepted: 3854Descrip ...