日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

JSP初級教程之跟我學(xué)JSP(八)_JSP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:JSP初級教程之跟我學(xué)JSP(七)
第七章“備注型”超長文本的操作——Clob類型數(shù)據(jù)的存取 存放 oracle 留言板的正文內(nèi)容,用VARCHAR2()是不行的,VARCHAR2()(可變長度的字符串)只能存4000字節(jié),也就是2000個漢字,這也太少了啊,查一下 數(shù)據(jù)庫 類型的資料,發(fā)現(xiàn)有這么幾個類型: LONG,2G

第八章 Blob類型數(shù)據(jù)的存取和使用第一個Servlet—— 圖片文件的操作

以下是我經(jīng)過改編得到的jsp代碼:
------------------------------upphoto.htm------------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標(biāo)題文檔</title>
head>

<body>
上傳圖片:
<form name="form1" method="post" action="upphoto.jsp">
<input name="id" type="text">
(輸入一個整數(shù)作為該圖片的ID)<br>
<input size="50" name="file" type="file">
<br>
<input type="submit" name="Submit" value="提交">
</form>
<p> </p>
<p> </p>
顯示圖片:<br>
<br>
<form name="form2" method="post" action="showphoto.jsp">
<input type="text" name="vid">
(輸入該圖片的ID)<br>
<input type="submit" name="Submit2" value="提交">
</form>
</body>
</html>
---------------------------------------------------------------------------
upphoto.htm包括兩個<form>,form1用于選擇要存于數(shù)據(jù)庫的圖片;form2用于顯示一張數(shù)據(jù)庫里的圖片。
-----------------------------upphoto.jsp----------------------------------
<%@ include file="include.inc"%>
<%@ page contentType="text/html;charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標(biāo)題文檔</title>
</head>

<body>
<%
int id=Integer.parseInt(request.getParameter("id"));
request.setCharacterEncoding("gb2312");
String f=request.getParameter("file");//得到路徑,如:c:\d\e.jpg
String fpath=f.replaceFirst("\\\\","\\\\\\\\");//把一個\變成兩個\,即路徑改成:c:\\d\e.jpg

Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
Class.forName(CLASSFORNAME);//載入驅(qū)動程式類別
con=DriverManager.getConnection(SERVANDDB);//建立數(shù)據(jù)庫連接
con.setAutoCommit(false);
String sql="insert into blb(id,blob) values("+id+",empty_blob())";//數(shù)據(jù)庫里那個表名叫blb,字段的名就叫blob
pstmt=con.prepareStatement(sql);//添加一條blob字段為空的記錄,
pstmt.executeUpdate();
pstmt=null;
sql="select * from blb where id="+id+" for update";
pstmt=con.prepareStatement(sql);//查找剛剛添加的那條記錄
rs=pstmt.executeQuery();
if (rs.next()) 
{
oracle.sql.BLOB osb = (oracle.sql.BLOB) rs.getBlob("blob");
//到數(shù)據(jù)庫的輸出流
OutputStream outStream = osb.getBinaryOutputStream();
//這里用一個文件模擬輸入流
File file = new File(fpath);
InputStream inStream = new FileInputStream(file);
//將輸入流寫到輸出流
byte[] b = new byte[osb.getBufferSize()];
int len = 0;
while ( (len = inStream.read(b)) != -1) 
{
outStream.write(b, 0, len);
}
//依次關(guān)閉(注意順序)
inStream.close();
outStream.flush();
outStream.close();
con.commit();
rs.close();
pstmt.close();
con.close();

分享:JSP初級教程之跟我學(xué)JSP(六)
第六章 jsp 實現(xiàn)畫柱狀統(tǒng)計圖 這一節(jié)的內(nèi)容是用jsp生成一個統(tǒng)計——統(tǒng)計一年內(nèi)每個月完成的報修任務(wù)量。 Java里和畫圖有關(guān)的是java.awt包,由于我構(gòu)想的圖只是由矩形組成,那么用到的方法也就這么幾個:fillRect,drawRect,setColor,setFont,drawString。

共3頁上一頁123下一頁
來源:模板無憂//所屬分類:JSP教程/更新時間:2010-03-10
相關(guān)JSP教程