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

jsp怎么写一个上传图片,不想用jspsmart组件,希望各位帮忙,说原理也可以,谢谢了!
如题,

------解决方案--------------------
为什么不用组件 用组件 又快 又方便
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<%@ page import= "com.jspsmart.upload.* "%>
<jsp:useBean id= "mySmartUpload " scope= "page " class= "com.jspsmart.upload.SmartUpload " />
<html>
<head>
<title> 上载附件 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
</head>
<body>
<center> 正在上传文件...

<%

//上载附件

try
{

mySmartUpload.initialize(pageContext);
mySmartUpload.service(request,response);
mySmartUpload.upload();
String fn=fn=mySmartUpload.getFiles().getFile(0).getFileName();
mySmartUpload.save( "upload/ ");//文件保存的目录为upload
out.println( "已经成功上传了文件,请查看 <a href=upload/ "+fn+ "> 这里 </a> ,看文件是否上传成功 ");
}
catch(Exception e)
{
e.printStackTrace();
}

%>
<a href=FileUpload.html> 重新上传 </a>
</body>
</html>