读书人

上传的图片保存在小弟我的文件夹下,而

发布时间: 2012-01-29 21:39:32 作者: rapoo

上传的图片保存在我的文件夹下,而路径保存在数据库中
要求:数据库用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="于记河问胖子驴肉馆" /> 

读书人网 >Java Web开发

热点推荐