package com.lianke.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.UUID;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import com.jspsmart.upload.SmartUploadException;
import com.lianke.util.DbConnection;
public class UpImageNew extends HttpServlet {
/**
* 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 {
this.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 {
Connection conn = null;
PreparedStatement ps = null;
//HttpSession session = request.getSession();
//String sessionID = session.getId();
//
// 实例化上载bean
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.SmartUpload();
// 初始化
response.getContentType();
JspFactory fac = JspFactory.getDefaultFactory();
PageContext pageContext = fac.getPageContext(this, request, response,
null, false, JspWriter.DEFAULT_BUFFER, true);
mySmartUpload.initialize(pageContext);
// 设置上载的最大值
mySmartUpload.setMaxFileSize(500 * 1024 * 1024);
// 上载文件
try {
mySmartUpload.upload();
// 循环取得所有上载的文件
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
// 取得上载的文件
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(
i);
if (!myFile.isMissing()) {
// 取得文件全名
String myFileName = myFile.getFileName();
// 取得不带后缀的文件名
String suffix = myFileName.substring(0, myFileName
.lastIndexOf("."));
// 取得后缀名
String ext = mySmartUpload.getFiles().getFile(0).getFileExt();
if (ext.equals("exe ")) {
System.out.println("上传文件不能为EXE文件 ");
return;
}
// 取得文件的大小
int fileSize = myFile.getSize();
// 保存路径
String aa = getServletContext().getRealPath("/") + "upfile\\";
String trace = aa + myFileName;
// 取得别的参数
String explain = (String) mySmartUpload.getRequest().getParameter("text ");
String send = (String) mySmartUpload.getRequest().getParameter("send");
// 将文件保存在服务器端
System.out.println(trace);
myFile.saveAs(trace,com.jspsmart.upload.File.SAVEAS_PHYSICAL);
// 将上载的文件保存到数据库中
// 将文件读到流中
java.io.File file = new java.io.File(trace);
java.io.FileInputStream fis = new java.io.FileInputStream(file);
// 打开数据库
UUID idSno=UUID.randomUUID();
conn = DbConnection.getConnection();
ps = conn.prepareStatement("insert into SDLY_PIC(ID_SNO,OC_FLAG,C_PIC,OC_YXBZ,DT_SCSJ,OC_CZY) values (?,?,?,?,sysdate,?)");
ps.setString(1, idSno.toString());
ps.setString(2, "01");
ps.setBinaryStream(3, fis, (int)file.length());
ps.setString(4, "T");
ps.setString(5, "admin");
ps.execute();
fis.close();
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(ps!=null)ps.close();
if(conn!=null)conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
iframe图片上传接口(某项目中的图片接口,图片存成oracle中的Blob)
共75个文件
class:18个
html:12个
jsp:10个
需积分: 33 8 下载量 39 浏览量
2011-03-08
17:44:02
上传
评论
收藏 9.63MB RAR 举报
温馨提示
iframe图片上传,某项目中的图片接口,图片存成oracle中的Blob,ID生成策略调用存储过程,实现图片的新增,修改,删除,预览的功能。附全部代码,数据库,希望跟朋友们交流下。
资源推荐
资源详情
资源评论
收起资源包目录
UpLoadImage.rar (75个子文件)
UpLoadImage
test.html 3KB
.project 1KB
WEB-INF
web.xml 3KB
lib
jstl-1.2.jar 363KB
ojdbc14.jar 1.47MB
jsmartcom_zh_CN.jar 13KB
jsf-api.jar 278KB
jsf-impl.jar 1.06MB
classes12.jar 1.52MB
classes
com
lianke
action
UpImageNew.class 5KB
Test.class 2KB
UpImageB.class 5KB
UpImageA.class 5KB
LoadImage.class 3KB
UpImage.class 5KB
Collable.class 2KB
util
DbConnection.class 910B
testFile.class 1KB
.settings
org.eclipse.jdt.ui.prefs 99B
org.eclipse.core.resources.prefs 142B
org.eclipse.jdt.core.prefs 633B
org.eclipse.ltk.core.refactoring.prefs 137B
META-INF
MANIFEST.MF 39B
.mymetadata 306B
WebRoot
test.html 3KB
WEB-INF
web.xml 3KB
lib
ojdbc14.jar 1.47MB
jsmartcom_zh_CN.jar 13KB
classes12.jar 1.52MB
classes
com
lianke
action
UpImageNew.class 5KB
Test.class 2KB
UpImageB.class 5KB
UpImageA.class 5KB
LoadImage.class 3KB
UpImage.class 5KB
Collable.class 2KB
util
DbConnection.class 911B
testFile.class 1KB
META-INF
MANIFEST.MF 39B
error.html 280B
fj_imageUpLoad.jsp 3KB
imageUpLoadB.jsp 4KB
imageUpLoadA.jsp 4KB
image.html 786B
image.jsp 1KB
upload
真的是中文名字.jpg 606KB
Thumbs.db 94KB
Tulips.jpg 606KB
moreImage.html 743B
imageUpLoad.jsp 4KB
index.html 5KB
indexTest.html 5KB
error.html 280B
fj_imageUpLoad.jsp 3KB
imageUpLoadB.jsp 4KB
imageUpLoadA.jsp 4KB
image.html 786B
image.jsp 1KB
upload
真的是中文名字.jpg 606KB
Thumbs.db 94KB
Tulips.jpg 606KB
.myeclipse
moreImage.html 743B
src
com
lianke
action
LoadImage.java 2KB
UpImageA.java 4KB
UpImageB.java 4KB
Test.java 1KB
UpImage.java 4KB
UpImageNew.java 4KB
Collable.java 1KB
testFile.java 1KB
util
DbConnection.java 506B
imageUpLoad.jsp 4KB
.classpath 582B
index.html 5KB
indexTest.html 5KB
共 75 条
- 1
资源评论
蒙奇·D·路飞-
- 粉丝: 5707
- 资源: 406
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功