- 浏览: 720356 次
- 性别:
- 来自: 湖北
文章分类
最新评论
-
SE_XiaoFeng:
用mysqldump命令行导出。这个报错唉。错误提示信息如下: ...
linux下如何导入导出MySQL数据库 -
SE_XiaoFeng:
文章写的干脆了当,我喜欢!
linux下如何导入导出MySQL数据库 -
niky6688:
网站咋打不开呢
beckham herms birki ...
【原创】上周给公司新做了一个网站,请大家审阅! -
niky6688:
哈哈
new chanel bags 2012
burbe ...
今天我抢了一个咪咪??? -
ydsakyclguozi:
...
jsp资源管理器也可能是木马
一个使用jspSmartUpload控件上传文件的例子
view plaincopy to clipboardprint?
package cn.edu.hbcit.ips.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import cn.edu.hbcit.ips.bean.ConnBean;
import cn.edu.hbcit.ips.bean.FileOperate;
import com.jspsmart.upload.*;
public class ExcelUpload extends HttpServlet {
private ServletConfig config;
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
protected final Logger log = Logger.getLogger(ExcelUpload.class.getName());
/**
* Constructor of the object.
*/
public ExcelUpload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
int countFile = 0;
String realPath = "";
String oldFilename ="";
SmartUpload su = new SmartUpload(); //实例化jspSmartUpload
su.initialize(config, request, response);// 初始化SmartUpload
su.setAllowedFilesList("xls"); //允许上传的文件类型(中间用,隔开)
su.setMaxFileSize(1 * 1024 * 1024); //声明上传文件最大容量
log.debug("Uploading...");
try{
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
oldFilename = file.getFileName();//得到原文件名
log.debug("原文件名为:"+oldFilename);
FileOperate fo = new FileOperate();
if(file.getFileExt().equalsIgnoreCase("xls")){//判断文件扩展名是否为xls
//将文件另存为
if (!file.isMissing()) {
realPath = request.getRealPath("/")+"UserFiles\\";
// su.save(realPath);
realPath += fo.generateRandomFilename()+"xls";
log.debug("当前路径是:"+realPath);
file.saveAs(realPath, su.SAVE_PHYSICAL);
log.debug("上传文件大小:"+file.getSize());
}
}
}catch(Exception e){
log.error(e.getMessage());
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
}
package cn.edu.hbcit.ips.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import cn.edu.hbcit.ips.bean.ConnBean;
import cn.edu.hbcit.ips.bean.FileOperate;
import com.jspsmart.upload.*;
public class ExcelUpload extends HttpServlet {
private ServletConfig config;
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
protected final Logger log = Logger.getLogger(ExcelUpload.class.getName());
/**
* Constructor of the object.
*/
public ExcelUpload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
int countFile = 0;
String realPath = "";
String oldFilename ="";
SmartUpload su = new SmartUpload(); //实例化jspSmartUpload
su.initialize(config, request, response);// 初始化SmartUpload
su.setAllowedFilesList("xls"); //允许上传的文件类型(中间用,隔开)
su.setMaxFileSize(1 * 1024 * 1024); //声明上传文件最大容量
log.debug("Uploading...");
try{
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
oldFilename = file.getFileName();//得到原文件名
log.debug("原文件名为:"+oldFilename);
FileOperate fo = new FileOperate();
if(file.getFileExt().equalsIgnoreCase("xls")){//判断文件扩展名是否为xls
//将文件另存为
if (!file.isMissing()) {
realPath = request.getRealPath("/")+"UserFiles\\";
// su.save(realPath);
realPath += fo.generateRandomFilename()+"xls";
log.debug("当前路径是:"+realPath);
file.saveAs(realPath, su.SAVE_PHYSICAL);
log.debug("上传文件大小:"+file.getSize());
}
}
}catch(Exception e){
log.error(e.getMessage());
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
}
view plaincopy to clipboardprint?
package cn.edu.hbcit.ips.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import cn.edu.hbcit.ips.bean.ConnBean;
import cn.edu.hbcit.ips.bean.FileOperate;
import com.jspsmart.upload.*;
public class ExcelUpload extends HttpServlet {
private ServletConfig config;
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
protected final Logger log = Logger.getLogger(ExcelUpload.class.getName());
/**
* Constructor of the object.
*/
public ExcelUpload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
int countFile = 0;
String realPath = "";
String oldFilename ="";
SmartUpload su = new SmartUpload(); //实例化jspSmartUpload
su.initialize(config, request, response);// 初始化SmartUpload
su.setAllowedFilesList("xls"); //允许上传的文件类型(中间用,隔开)
su.setMaxFileSize(1 * 1024 * 1024); //声明上传文件最大容量
log.debug("Uploading...");
try{
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
oldFilename = file.getFileName();//得到原文件名
log.debug("原文件名为:"+oldFilename);
FileOperate fo = new FileOperate();
if(file.getFileExt().equalsIgnoreCase("xls")){//判断文件扩展名是否为xls
//将文件另存为
if (!file.isMissing()) {
realPath = request.getRealPath("/")+"UserFiles\\";
// su.save(realPath);
realPath += fo.generateRandomFilename()+"xls";
log.debug("当前路径是:"+realPath);
file.saveAs(realPath, su.SAVE_PHYSICAL);
log.debug("上传文件大小:"+file.getSize());
}
}
}catch(Exception e){
log.error(e.getMessage());
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
}
package cn.edu.hbcit.ips.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import cn.edu.hbcit.ips.bean.ConnBean;
import cn.edu.hbcit.ips.bean.FileOperate;
import com.jspsmart.upload.*;
public class ExcelUpload extends HttpServlet {
private ServletConfig config;
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
protected final Logger log = Logger.getLogger(ExcelUpload.class.getName());
/**
* Constructor of the object.
*/
public ExcelUpload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
int countFile = 0;
String realPath = "";
String oldFilename ="";
SmartUpload su = new SmartUpload(); //实例化jspSmartUpload
su.initialize(config, request, response);// 初始化SmartUpload
su.setAllowedFilesList("xls"); //允许上传的文件类型(中间用,隔开)
su.setMaxFileSize(1 * 1024 * 1024); //声明上传文件最大容量
log.debug("Uploading...");
try{
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
oldFilename = file.getFileName();//得到原文件名
log.debug("原文件名为:"+oldFilename);
FileOperate fo = new FileOperate();
if(file.getFileExt().equalsIgnoreCase("xls")){//判断文件扩展名是否为xls
//将文件另存为
if (!file.isMissing()) {
realPath = request.getRealPath("/")+"UserFiles\\";
// su.save(realPath);
realPath += fo.generateRandomFilename()+"xls";
log.debug("当前路径是:"+realPath);
file.saveAs(realPath, su.SAVE_PHYSICAL);
log.debug("上传文件大小:"+file.getSize());
}
}
}catch(Exception e){
log.error(e.getMessage());
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
}
发表评论
-
属性文件的读取 Java
2010-12-11 08:51 1163import java.util.ResourceBu ... -
【精华】Java项目生成静态页面
2010-12-11 08:47 1196需转载,请注明转载出处!本文地址: http://blog. ... -
【珍藏版】微软等数据结构+算法面试100题全部出炉[100题首次完整亮相]
2010-12-06 16:33 2836转至: http://blog.csdn.net/v_JULY ... -
【原创】Log4j 日志文件 使用
2010-12-02 11:37 1190log4j.properties 代码 log4j.ro ... -
【精华】保护自己的网站资源
2010-11-19 08:03 1168禁止用“另存为”保存页面 <head> < ... -
【精华】Window.Open()网页弹出窗口大全
2010-11-16 18:01 1510【1、最基本的弹出窗口代码】 <!--<br ... -
【精华】页面右下角弹出类似QQ或MSN的消息提示
2010-11-05 16:36 983具体实现见 附件 主要是 针对 在框架中 如何实现 后下 ... -
【原创】苦恼了1个星期的DIV 滚动条置底, 今天终于实现了!!!
2010-11-05 10:58 3412<script type="text/ja ... -
【急救......】Could not find the main class.program will exit
2010-11-01 17:23 1595Java中Could not find the main cl ... -
屏蔽 F5 刷新键
2010-10-28 11:09 736<script language="JavaS ... -
web页面中按ESC关闭窗口
2010-10-28 11:04 1372<script language="jav ... -
web页面中如果想让用户复制页面内容粘贴时加入一些自定义信息
2010-10-28 11:04 798如果让用户复制你网站上的信息到别处粘贴时,附加自定义信息可以采 ... -
防止页面被多次提交
2010-10-28 11:03 18331. javascript ,设置一个变量,只允许提交一 ... -
Javascript打印代码
2010-10-18 14:38 864Javascript打印代码 实现打印功能的javasc ... -
【原创】struts+mysql+jsp 分页源码
2010-09-16 10:42 877具体代码见附件 一起学习,xf.zhouwenjun@163 ... -
【原创】struts 动态 设置radio 与 select 的默认值
2010-08-06 13:10 1607运行效果见 附件,有好的解决方法请分享xf.zhouwenju ... -
【原创】平时编码中积累的,非常好用,且很全的【时间工具类】
2010-07-21 17:42 862具体java类 请下载附件!烦请大家一起完善完善,请给我也分享 ... -
【原创】苦苦寻找的: ajax 定时读取数据,无刷新在页面显示
2010-07-19 17:17 989demo 见附件 -
【绝】在web工程下 调用js 日历控件 报错【missing ( before function parameters)
2010-07-09 11:28 1067报错代码 function document.onclick( ... -
【精髓】非常好用的日历控件,可以自由的选择日期 时分秒
2010-07-09 10:57 17111、Calendar.js代码如下 省略! 具体内容 ...
相关推荐
使用jspSmartUpload实现文件上传下载,包含SmartUpload方法注解、上传示例及组件包
jsp+jspsmartupload控件上传图片至数据库源码采用的是jsp+servlet+javabean,数据库是server 2005,关键是传地址
jsp servlet 上传例子 jspsmartupload jsp servlet 上传例子 jspsmartupload jsp servlet 上传例子 jspsmartupload
使用jspSmartUpload组件在jsp中实现上传和下载
使用JSP实现上传下载文件jspSmartUpload 里面讲述怎么用jsp实现
JspSmartUpload上传文件实例,基于JspSmartUpload组件的文件上传实例,JspSmartUpload 上传类,在JSP中进行文件上传的类,内含文档和使用例子。这个在JSP编程环境下,使用频率还是挺高的,这个例子可帮助你在JSp环境...
jspsmartupload.zip+例子
最近实验室做了一个项目,使用jspsmartupload来实现的文件的上传下载,原来在windows平台运行的挺好,但是后来系统移植到linux平台上,结果在上传或下载的文件名中有中文时就会出现乱码。后来查了网上一些人的解决...
NULL 博文链接:https://systemxgl.iteye.com/blog/267472
下载即可运行,但是这个压缩包不支持中文名称的文件下载功能,我上传了一个可以下载中文的不会乱码的jspSmartUpload 组件,网址:http://download.csdn.net/detail/huahuahailang/4265620 照着使用,即可下载中文。
采用smartUpload控件文件上传采用smartUpload控件文件上传采用smartUpload控件文件上传
jspSmartUpload实现文件上传下载
JspSmartUpload实现多文件上传
详细介绍使用jspSmartUpload来上传文件的好处和具体用法
2、有用jspSmartupload制作一个文件上传和下载的例子,其制作的例子能够上传到数据库中; 3、还用ExtJS制作的多文件同时上传的例子,后台也是用Servlet处理。 4、用Servlet要注意web.xml映射的配置。
二、相关类说明篇 ㈠ File类 这个类包装了一个上传文件的所有信息。通过它,可以得到上传文件的文件名、文件大小、扩展名、文件数据等信息 File类主要提供以下方法 1、saveAs作用:将文件换名另存...
JspSmartUpload文件上传下载.zip
NULL 博文链接:https://jingrenlang.iteye.com/blog/356351
jsp技术SmartUpload文件上传例子
文件上传组件JspSmartUpload 文件上传组件JspSmartUpload