JSP图片上传
如何在JSP中将图片上传到指定目录,并将其路径保存到数据库中.上网找了好多这方面的资料可都一点都不实用,
请各位大哥们指点高招!
搜索更多相关主题的帖子:
图片 上传 路径 JSP
----------------解决方案--------------------------------------------------------
用jspsmartupload或者自己写。读二进制流再存。其实说起来简单。做起来有点难度。就用jspsmartupload吧
----------------解决方案--------------------------------------------------------
不懂!!!!!!
----------------解决方案--------------------------------------------------------
具体实现步骤是什么啊?
----------------解决方案--------------------------------------------------------
买本书看就有啦
----------------解决方案--------------------------------------------------------
初学者路过
----------------解决方案--------------------------------------------------------
图片保存在文件夹中...
数据库只保存路径....
----------------解决方案--------------------------------------------------------
自己去网上下个javazoom的组件就可以了,具体内容可以在网上学习!
----------------解决方案--------------------------------------------------------
通过文件上传组件实现
1.commons-fileipload + commons-io
2.如前面提到的 jspsmartupload
自己去下载这些jar吧
----------------解决方案--------------------------------------------------------
jspsmartupload:
先将smartupload.jar拷贝到WEB-INF/lib下
index:
<html>
<head>
<title>文件上传</title>
</head>
<body>
<h2>文件上传</h2>
<form name="myform" enctype="multipart/form-data" method="post" action="UploadDemo.jsp">
<p>文 件 名:<input type="text" name="fileName"></p>
<p>上传文件:<input type="file" name="file" size="20" maxlength="20"></p>
<input type="submit" value="上传">
<input type="reset" value="重置">
</form>
</body>
</html>
upload.jsp:
<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>文件上传</title>
</head>
<body>
<h2>文件上传</h2>
<jsp:useBean id="smart" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
// 计算文件上传个数
int count = 1;
// 上传的初始化
smart.initialize(pageContext);
// 限制上传的文件大小为 5MB
smart.setMaxFileSize(5 * 1024 * 1024);
// 准备上传
smart.upload();
String name = smart.getRequest().getParameter("fileName");
try
{
if(name == null || "".equals(name))
{
// 取得文件原始名称
name = smart.getFiles().getFile(0).getFileName();
// 保存文件(将文件取名为原文件名保存在站点根目录下)
count = smart.save("/");
}
else
{
// 累加扩展名
name += "." + smart.getFiles().getFile(0).getFileExt();
// 使用自定义文件名保存上传文件
smart.getFiles().getFile(0).saveAs("/" + name + "." + smart.getFiles().getFile(0).getFileExt());
}
// 显示上传文件个数
out.print("您成功上传" + count + "个文件");
out.print("<br>");
out.print("文件名为" + name);
}
catch(Exception e)
{
out.print(e.toString());
}
%>
</body>
</html>
----------------解决方案--------------------------------------------------------