realization of image database storage and display
based on JSP
1, Introduction
database applications, especially web-based database applications, often involve the storage and display of picture information. Usually we use the method is to display the picture in a specific directory, in the database to save the name of the picture, in the JSP set up the corresponding data source, the use of database access technology to process picture information. However, if we want to display the picture dynamically, the above method will not meet the need. We have to store the pictures in the database and then dynamically display the pictures we need by programming them. In practice, we can use the JSP programming mode to realize the image database storage and display.
2, establish the background database
assumes that the processing is the picture news, then we can establish the corresponding database and the data table object. The SQL script for the data table structure we want to access is as follows:
if exists (SELECT * from dbo.sysobjects where id =
object_id (N ' [dbo].[ Picturenews] Andobjectproperty (ID, N ' isusertable ') = 1)
drop TABLE [dbo]. [Picturenews]
Go
CREATE TABLE [dbo]. [Picturenews] (
[id] [int] IDENTITY (1, 1) not NULL,
[Image] [image] NULL,
[content] [varchar] (m) COLLATE chinese_prc_ci_as NULL,
[detail] [varchar] (5000) COLLATE chinese_prc_ci_as NULL
) on [PRIMARY] textimage_on [PRIMARY]
Go
Table picturenews, the field ID is identified as an automatic increment of 1 for each row of data stored. Field Image
is used to store picture information with the data type "image".
3, storing binary pictures to the database
start Dreamweaver mx, create a new JSP file. The code looks like the following.
<%@ page contenttype= "text/html;charset=gb2312"%>
<HTML>
<HEAD>
<TITLE> Storage pictures </TITLE>
</HEAD>
<body>
<!--the form below will pass the data to the testimage.jsp file--> The Post method
<form method=post action= "testimage.jsp" >
News title: <input type= "text" name= "content" ><BR>
News Picture: <input type= "file" name= "image" ><BR>
news content: <textarea name= "Txtmail" rows= "cols=" "style=" Border-bottom: #000000 1px solid; Border-left: #000000 1px solid; Border-right: #000000 1px solid; Border-top: #000000 1px solid; font-size:9pt; height:200px; width:100% "wrap=" Physical ></textarea><br>