Realization of storing and displaying database pictures with JSP

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.