日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

html5 java 图片上传_java实现图片上传至服务器并显示,如何做?希望要具体的代码实现...

發(fā)布時(shí)間:2025/3/11 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html5 java 图片上传_java实现图片上传至服务器并显示,如何做?希望要具体的代码实现... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

展開全部

有兩種方法一是用上傳的組建jspSmartUpload的Request,

還有一種不用組建,但在e69da5e6ba9062616964757a686964616f31333238653233form表單中不能加入ENCTYPE= "multipart/form-data "

我給你的案例吧

建立后臺數(shù)據(jù)庫

if exists (select * from dbo.sysobjects

where id = object_id(N'[dbo].[p]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[p]

GO

CREATE TABLE [dbo].[p] (

[picid] [int] IDENTITY (1, 1) NOT NULL ,

[picname] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,

[pic] [image] NULL

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

3.向數(shù)據(jù)庫存儲二進(jìn)制圖片

啟動Dreamweaver MX后,新建一個(gè)JSP文件。其代碼如下所示。

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()

+":"+request.getServerPort()+path+"/";

%>

My JSP 'InputImage.jsp' starting page

題目

圖片

將此文件保存為InputImage.jsp文件,其中testimage.jsp文件是用來將圖片數(shù)據(jù)存入數(shù)據(jù)庫的,具體代碼如下所示:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+

":"+request.getServerPort()+path+"/";

%>

My JSP 'testimage.jsp' starting page

request.setCharacterEncoding("gb2312");

//建立Statement對象

String picname=request.getParameter("picname");

String pic=request.getParameter("pic");

//獲得所要顯示圖片的標(biāo)題、存儲路徑、內(nèi)容,并進(jìn)行中文編碼

FileInputStream str=new FileInputStream(pic);

String sql="insert into p(picname,pic) values(?,?)";

PreparedStatement pstmt=conn.getPreparedStatement(sql);

pstmt.setString(1,picname);

pstmt.setBinaryStream(2,str,str.available());

pstmt.execute();

//將數(shù)據(jù)存入數(shù)據(jù)庫

out.println("Success,You Have Insert an Image Successfully");

%>

4. 網(wǎng)頁中動態(tài)顯示圖片

接下來我們要編程從數(shù)據(jù)庫中取出圖片,其代碼如下所示。

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+

":"+request.getServerPort()+path+"/";

%>

My JSP 'testimageout.jsp' starting page

int id= Integer.parseInt(request.getParameter("picid"));

String sql = "select pic from p WHERE picid="+id;

ResultSet rs=conn.getResult(sql);

while(rs.next())

{

ServletOutputStream sout = response.getOutputStream();

//圖片輸出的輸出流

InputStream in = rs.getBinaryStream(1);

byte b[] = new byte[0x7a120];

for(int i = in.read(b); i != -1;)

{

sout.write(b);

//將緩沖區(qū)的輸入輸出到頁面

in.read(b);

}

sout.flush();

//輸入完畢,清除緩沖

sout.close();

}

%>

將此文件保存為testimageout.jsp文件。下一步要做的工作就是使用HTML標(biāo)記:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+

":"+request.getServerPort()+path+"/";

%>

My JSP 'lookpic.jsp' starting page

String sql = "select * from p";

ResultSet rs=conn.getResult(sql);

while(rs.next())

{

%>

" width="100" height="100">

}

rs.close();

%>

已贊過

已踩過<

你對這個(gè)回答的評價(jià)是?

評論

收起

總結(jié)

以上是生活随笔為你收集整理的html5 java 图片上传_java实现图片上传至服务器并显示,如何做?希望要具体的代码实现...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。