日期:2014-05-18  浏览次数:20760 次

jsp上传图片问题
jsp上传图片怎么解决啊,就是上传后保存到一个文件加中,同时获取图片的路径,谢谢啦

------解决方案--------------------
用SmartUpload处理的,供参考

<%--
文件名:do_upload.jsp
--%>
<%@ page contentType= "text/html; charset=gb2312 " language= "java "
import= "com.jspsmart.upload.*,java.sql.* "
errorPage= " "%>
<html>
<head>
<title> 文件上传处理页面 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
</head>

<body>
<%
Connection con;
ResultSet rs;
Statement stmt;


//数据库登录用户和密码
String user= "sa ";
String password= "sa ";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
String url= "jdbc:odbc:jspbook ";
con=DriverManager.getConnection(url,user,password);
//创建一个jdbc声明
stmt=con.createStatement();


SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.upload();
String title=su.getRequest().getParameter( "title ");
String Remark=su.getRequest().getParameter( "Remark ");

int count = su.save( "/upload ");
out.println(count+ "个文件上传成功! <br> ");
//out.println( "TEST= "+su.getRequest().getParameter( "TEST ")+ " <BR> <BR> ");
System.out.println( "2 ");
for (int i=0;i <su.getFiles().getCount();i++)
{
System.out.println( "3 ");
com.jspsmart.upload.File file = su.getFiles().getFile(i);

if (file.isMissing()) continue;

String filename=file.getFileName();
int ifilelength=file.getSize();
String sfilelength=Integer.toString(ifilelength);
String filetype=file.getFileExt();
java.util.Date dt = new java.util.Date();
String suploadtime=String.valueOf(1900+dt.getYear())+ "- "+String.valueOf(1+dt.getMonth())
+ "- "+String.valueOf(dt.getDate());


stmt.executeUpdate( "insert into uploadfileinfo(filename,title, "
+ "filetype,fiellength,uploadtime,description) "
+ "values( ' "+filename+ " ', ' "+title+ " ', ' "+filetype+ " ', ' "
+sfilelength+ " ', ' "+suploadtime+ " ', ' "+Remark+ " ') ");


out.println( " <TABLE BORDER=1> ");
out.println( " <TR> <TD> 文件名: </TD> <TD> "+ filename + " </TD> </TR> ");
out.println( " <TR> <TD> 文件长度: </TD> <TD> " +sfilelength + " </TD> </TR> ");
out.println( " <TR> <TD> 文件类型: </TD> <TD> "+ filetype + " </TD> </TR> ");
//out.println( " <TR> <TD> 文件全名(FilePathName) </TD> <TD> "+ file.getFilePathName() + " </TD> </TR> ");
out.println( " </TABLE> <BR> ");
}
%>
</body>
</html>
------解决方案--------------------
发过去了

<%@ page contentType= "text/html;charset=GBK " %>
<%@ page language= "java " import= "com.jspsmart.upload.* "