ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:47.20KB ,
资源ID:16661505      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/16661505.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(jsp多文件上传到数据库Word文件下载.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

jsp多文件上传到数据库Word文件下载.docx

1、titleFile Uploadlink href=%=request.getContextPath()%/css/fileupload.css rel=stylesheet type=text/css/headbody bgcolor=#ccccccdiv style=padding-top: 30px; padding-left: 30pxfieldset style=width: 600px; border-color: #000000; 10pxlegendfont size=-1 color=#000000b上传图片/font/legenddiv class=ErrorDivs:fi

2、elderror/actionerror/divform action=fileUpload.action method=post theme=simple enctype=multipart/form-datatable border=1 width=500pxtrtd class=tableTDCenter 图片路径:/tdfile name=file cssClass=fileInput/ /tr colspan=2submit value=提交button/s:submit/tableform/fieldset/body/html很简单,就是个上传框和按钮,别的没有了。至于一些css就

3、是稍微的装饰装饰,一会也在下面写上!上传成功的画面:Image Listiterator value=#list id=picturedivfloatimg src=outPicture.action?id=下面我们看看struts2的配置文件:?xml version=1.0 encoding=DOCTYPE struts PUBLIC -/Apache Software Foundation/DTD Struts Configuration 2.0/ENhttp:/struts.apache.org/dtds/struts-2.0.dtdstrutsconstant name=struts

4、.custom.i18n.resources value=messageResource /struts.i18n.encodingpackage name=default extends=struts-default-上传-action name=fileUpload class=org.csdn.action.FileUploadActioninterceptor-ref name =defaultStackparam name =allowedTypes image/bmp,image/png,image/gif,image/jpg/paramparam name=maximumSize

5、404800result name=success/uploadSuccess.jspinput/fileUpload.jsp-输出显示-outPictureorg.csdn.action.OutPictureAction/package/struts至于里面的东西是什么,大家肯定根据名字一看就知道了。上面我引用了messageResource资源文件,为了显示错误消息。比如上传类型不正确,超过大小,以及上传失败。下面就是资源文件中的内容。struts.messages.error.content.type.not.allowed=The file you uploaded is not a

6、imagestruts.messages.error.file.too.large=this picutre is too largefileupload.fail=file upload is fail如果没有重新定义上面两个key的话,显示的会是struts2默认的错误消息,很是难看,也乱起八糟的。所以我重新定义了。接着我们就开始写上传和输出图片的action,以及相关的类信息上传的action:import java.io.File;import java.util.List;import org.csdn.service.FileUploadService;import org.csd

7、n.vo.Picture;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;/* * author closewubq */public class FileUploadAction extends ActionSupport private static final long serialVersionUID = 1L; private File file; public File getFile() return file; public void setFil

8、e(File file) this.file = file; /* * 上传文件 Override public String execute() FileUploadService fuservice=new FileUploadService(); if(fuservice.fileUpload(file) List list=fuservice.findAll(); ActionContext cxt=ActionContext.getContext(); cxt.put(list,list); return SUCCESS; else super.addActionError(this

9、.getText(fileupload.fail); return INPUT;非常简单,因为我只单纯的用了struts2,没有用spring。所以FileUploadService就硬编码写在里面了。、图片上传的主要业务类import java.io.FileInputStream;import java.io.InputStream;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.ArrayList;import org.csdn.

10、connection.GetConnection;public class FileUploadService * 上传图片到数据库 * param flie * return boolean * 上传是否成功 public boolean fileUpload(File flie) FileInputStream in = null; Connection conn = null; PreparedStatement ps = null; try in = new FileInputStream(flie); String sql = insert into savepicture(pict

11、ure) value(?); conn = GetConnection.getConn(); if (conn = null) System.out.println(连接为null); return false; ps = conn.prepareStatement(sql); ps.setBinaryStream(1, in, in.available(); if (ps.executeUpdate() 0) GetConnection.close(conn, ps, null); return true; else catch (Exception e) System.out.printl

12、n(e.getMessage(); * 检索所有图片 * return list * 返回所有图片记录 public List findAll() list = new ArrayList(); Picture pic = null; ResultSet rs = null;select id from savepicture return null; rs = ps.executeQuery(); while (rs.next() pic = new Picture(); pic.setId(rs.getInt(id list.add(pic); GetConnection.close(co

13、nn, ps, rs); return list; e.printStackTrace(); * 根据图片ID获取流对象 * param id * return InputStream public InputStream getPicById(int id) InputStream is = null;select picture from savepicture where id=? ps.setInt(1, id); if(rs.next() is = rs.getBinaryStream( return is; catch (Exception ex) ex.printStackTra

14、ce();简单的写了个jdbc链接的获取类。import java.sql.DriverManager;import java.sql.SQLException; * 获取数据库链接public class GetConnection * 获取数据库连接 * return Connection * 返回数据库连接 public static Connection getConn() Class.forName(com.mysql.jdbc.Driver).newInstance(); String url = jdbc:mysql:/localhost/csdn?user=root&passw

15、ord= Connection connection = DriverManager.getConnection(url); return connection; * 关闭连接释放资源 * param conn * param rs * param st public static void close(Connection conn,PreparedStatement ps,ResultSet rs) if(rs!=null) rs.close(); catch (SQLException e) if(ps! ps.close(); if(conn! conn.close();还有保存图片信

16、息的VOpublic class Picture private int id; public int getId() return id; public void setId(int id) this.id = id;输出图片信息的Actionimport javax.servlet.ServletOutputStream;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContex

17、t; * 图片输出 *public class OutPictureAction extends ActionSupport public String execute() throws Exception HttpServletRequest request = ServletActionContext.getRequest(); int id=Integer.parseInt(request.getParameter( FileUploadService service=new FileUploadService(); InputStream in=service.getPicById(id); HttpServletResponse response=ServletActionContext.getResponse(); response.setContentType(image/gif int size=in.available(); byte image=new bytesize; in.read(image); ServletOutputStream out=response.getOutputStream(); out.write(image);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1