如何在jsp中上传图像并将数据库存储为blob [英] how to upload a image in jsp and store database as blob

查看:94
本文介绍了如何在jsp中上传图像并将数据库存储为blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@page import="java.sql.*" %>
<html>
<form method="get" action="blobexcode.jsp" onsubmit="txtvalidate()">
<head>
    <style type="text/css">
    body{
        background-color:#d0e4fe;
    }
</style>    
</head>

<body>
    <table>
        <tr>
            <td>
                Customer Name&nbsp;<input type="text" name="Customername" id="customername">
            </td>
        </tr>
         <tr>
            <td>
                Customer Mob: <input type="text" onkeypress="return 
isNumberKey(event)" name="Customerphone" id="customerphone" >
            </td>
        </tr>
         <tr>
            <td>
                Upload File:&nbsp;&nbsp;<input type="file" id="f" name="f" >
            </td>
        </tr>
         <tr>
            <td>
                <input type="submit" value="SUBMIT" id="submit">
            </td>
        </tr>

     <script type="text/javascript">
        function isNumberKey(evt)
        {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
               return false;
            else
               return true;
         }
     </script>

     <script type="text/javascript">
         function txtvalidate()
         {
            if(document.getElementById("customername").value=="" ||
               document.getElementById("customerphone").value=="")
            { 
               alert("Fill all fields");
               return false;
               document.Customername.focus();
            }
            else
               return true;
        }
    </script>

    </table>
</body>
</form>
</html>

推荐答案

阅读以下文章,以在db中存储图像.本示例不使用JSP http://java-x.blogspot .com/2007/01/handling-oracle-large-objects-with-jdbc.html

Read the following article for storing image in db. This example does not use JSP http://java-x.blogspot.com/2007/01/handling-oracle-large-objects-with-jdbc.html

一旦您了解了上述文章,就可以使用commons-file upload上传文件,并检索已上传文件的inputstream并将其插入db中.

Once you have understanding of the article stated above you can use commons-file upload to upload the file and retrieve the inputstream of uploaded file and insert it in db.

有关文件上传的帮助,请参阅以下文章

Refer to following articles for help on file upload

http://commons.apache.org/fileupload/using.html

http://www.theserverside.com/news/1365153/HttpClient-和-FileUpload

这篇关于如何在jsp中上传图像并将数据库存储为blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆