日期:2014-05-17  浏览次数:20603 次

上传的图片保存在我的文件夹下,而路径保存在数据库中
要求:数据库用SQL SERVER2000 上传的图片保存在我的文件夹下,而路径保存在数据库中,能够从数据库中读取查看图片,
求高手给出源代码。

------解决方案--------------------

HTML code

<html>

    <head>

        <title>Upload</title>

    </head>

    <body>

        <table border="0" align="center" cellpadding="0" cellspacing="0">

            <tr>

                <td height="45" align="center" valign="middle">
                    <form action="index.jsp" method="post"
                        enctype="multipart/form-data" name="form1">

                        <input type="file" name="file">

                        <input type="submit" name="Submit" value="Upload">

                    </form>
                </td>

            </tr>

        </table>

    </body>

</html>

------解决方案--------------------
String filePath = request.getSession().getServletContext().getRealPath("文件夹名");

filePath += "/文件名";

File file = new File(filePath);

FileOutputStream fos = new FileOutputStream(imgPath);

fos.write(formFile.getFileData());//struts上传FormFile

fos.flush();

fos.close();
------解决方案--------------------
String filePath = request.getSession().getServletContext().getRealPath("文件夹名"); 

filePath += "/文件名"; 

File file = new File(filePath); 

FileOutputStream fos = new FileOutputStream(imgPath); 

fos.write(formFile.getFileData());//struts上传FormFile 

fos.flush(); 

fos.close();

这个很简单啊
------解决方案--------------------
恩这个问题 也困扰着我呢
帮忙顶着~~
确实 如果直接从数据库拿出来 他的现实就是
Java code

<img width="80" height="60" src="F:\tomcat6018\webapps\hahafanProject\img\shangchuan\restaurant\1017.jpg"
alt="于记河问胖子驴肉馆" />