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. Setting up a background database
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. Store binary pictures to the database
When you start Dreamweaver mx, create a new JSP file. The code looks like the following.
<%@ page contenttype= "text/html;charset=gb2312"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername ()
+ ":" +request.getserverport () +path+ "/";
%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<base href= "<%=basePath%>" >
<title>my JSP ' inputimage.jsp ' starting page</title>
<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache" >
<meta http-equiv= "Expires" content= "0" >
<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" >
<meta http-equiv= "description" content= "This are my page" >
<!--
<link rel= "stylesheet" type= "Text/css" href= "Styles.css" >
-->
<body>
<form action= "testimage.jsp" method= "POST" ><br>
Title <input name= "Picname" type= "text" ><br>
Picture <input name= "pic" type= "file" ><br>
<input type= "Submit" Name= "Button1" value= "submitted" ><br>
</form>
</body>